ext.pylons Adjacency List Relationship problem with admin app

8 views
Skip to first unread message

ballparkfh

unread,
Jan 17, 2009, 3:22:52 PM1/17/09
to FormAlchemy
I am attempting a recursive relationship (http://www.sqlalchemy.org/
docs/05/mappers.html#adjacency-list-relationships). The problem seems
to be when I'm creating a new object. I have to set the
super_category to null, because there aren't any. So my first
category will be my top level.

Here is my model:

import sqlalchemy as sa
from sqlalchemy import orm
import meta

t_categories = sa.Table("categories", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("name", sa.types.String(50), nullable=False),
sa.Column("super_category_id", sa.types.Integer, sa.ForeignKey
("categories.id"))
)

class Category(object): pass

orm.mapper(Category, t_categories, properties = {
"super_category" : orm.relation(Category, remote_side=
[t_tasks.c.id])
})

Jonathan ellis

unread,
Jan 17, 2009, 3:27:36 PM1/17/09
to forma...@googlegroups.com
Sorry, what is the problem exactly?

-Jonathan

On Jan 17, 2009, at 2:22 PM, ballparkfh

ballparkfh

unread,
Jan 17, 2009, 3:32:55 PM1/17/09
to FormAlchemy
I apologize. :) I get the following error when adding my first
category (top level category / no super category)...

KeyError: "Key not found: u'Category--super_category_id'"

I can't get to the stack trace right now, but I can send that later if
that will help.

ballparkfh

unread,
Jan 18, 2009, 8:51:06 AM1/18/09
to FormAlchemy
Below is the traceback. The actual name of my model is Task. I
changed the name in the above message to try to make it easier to
understand what I was trying to accomplish. I am going to download
Wing IDE to see if it helps me figure out the problem. Thanks so much
for any help you can offer.

Frank


File '/home/frank/dev/formalchemy-trunk/formalchemy/ext/pylons/
admin.py', line 161 in edit
if c.fs.validate():
File '/home/frank/dev/formalchemy-trunk/formalchemy/forms.py', line
292 in validate
return AbstractFieldSet.validate(self)
File '/home/frank/dev/formalchemy-trunk/formalchemy/forms.py', line 71
in validate
success = field._validate() and success
File '/home/frank/dev/formalchemy-trunk/formalchemy/fields.py', line
620 in _validate
value = self._deserialize()
File '/home/frank/dev/formalchemy-trunk/formalchemy/fields.py', line
1086 in _deserialize
return self.renderer.deserialize()
File '/home/frank/dev/formalchemy-trunk/formalchemy/fields.py', line
148 in deserialize
return self._deserialize(self._serialized_value())
File '/home/frank/dev/formalchemy-trunk/formalchemy/fields.py', line
132 in _serialized_value
return self._params.getone(self.name)
File '/usr/lib/python2.5/site-packages/Paste-1.7.2-py2.5.egg/paste/
util/multidict.py', line 281 in getone
return self._decode_value(self.multi.getone(key))
File '/usr/lib/python2.5/site-packages/Paste-1.7.2-py2.5.egg/paste/
util/multidict.py', line 68 in getone
raise KeyError('Key not found: %r' % key)
KeyError: "Key not found: u'Task--super_task_id'"

On Jan 17, 2:32 pm, ballparkfh <frank.henard.q...@statefarm.com>
wrote:

Jonathan ellis

unread,
Jan 18, 2009, 12:45:05 PM1/18/09
to forma...@googlegroups.com
Ok, we have your table, model and traceback -- did I miss where you
posted your fs configure and the rest of your controller code?

Wild guess: try setting default=None in your table on the super column.

-Jonathan

ballparkfh

unread,
Jan 19, 2009, 6:59:34 AM1/19/09
to FormAlchemy
Hello, I tried the default=None, and that didn't work. Here is my
Admin.py controller code. Is there other controller code you need?

I'm not sure what you mean by fs configure.

Thanks,
Frank

import logging
from timetracker.lib.base import *
from timetracker import model
from formalchemy.ext.pylons.admin import FormAlchemyAdminController

log = logging.getLogger(__name__)

class AdminControllerBase(BaseController):
model = model # where your SQLAlchemy mappers are
forms = None # module containing FormAlchemy fieldsets definitions
def Session(self): # Session factory
AdminControllerBase.Session = model.meta.Session
return AdminControllerBase.Session

AdminController = FormAlchemyAdminController(AdminControllerBase)

On Jan 18, 11:45 am, Jonathan ellis <jbel...@gmail.com> wrote:
> Ok, we have your table, model and traceback -- did I miss where you  
> posted your fs configure and the rest of your controller code?
>
> Wild guess: try setting default=None in your table on the super column.
>
> -Jonathan
>

Jonathan Ellis

unread,
Jan 19, 2009, 8:27:31 AM1/19/09
to forma...@googlegroups.com
Definitely a FA bug -- it should realize that super_category_id is
superceded by the super_category relation but it is not, probably b/c
it doesn't expect a recursive FK.

ballparkfh

unread,
Jan 19, 2009, 9:29:16 AM1/19/09
to FormAlchemy
Ok. Well I wish I knew enough to fix it. :)

Frank
> >> >> that will help.- Hide quoted text -
>
> - Show quoted text -

ballparkfh

unread,
Jan 19, 2009, 9:59:20 PM1/19/09
to FormAlchemy
Should I log an issue for this?

On Jan 19, 7:27 am, Jonathan Ellis <jbel...@gmail.com> wrote:

Jonathan Ellis

unread,
Jan 19, 2009, 10:33:27 PM1/19/09
to forma...@googlegroups.com
try with r635.

if that doesn't work, please post the html that the form is rendering as.

-Jonathan

ballparkfh

unread,
Jan 20, 2009, 8:29:10 AM1/20/09
to FormAlchemy
Again, I apologize, but I don't know what r635 is.

Here is the html the create form is rendering.


<html>
<head>
<style media="screen" type="text/css"><!-- @import url(/admin/
static_contents/admin.css); --></style>




</head>
<div>
<a href="/admin">
&lt;&lt; Models
</a>
</div>

<body>
<h1>New object Task </h1>
<form method="post">


<div>
<label class="field_req" for="Task--name">Name</label>
<input id="Task--name" maxlength="50" name="Task--name" type="text" /
>
</div>
<script type="text/javascript">
//<![CDATA[
document.getElementById("Task--name").focus();
//]]>
</script>
<div>
<label class="field_opt" for="Task--super_task_id">Super task</
label>

<select id="Task--super_task_id" name="Task--super_task_id"></
select>
</div>

<div>
<input type="submit">
<input type="button" value="Cancel"
onclick="javascript:window.location = '/admin/Task'" />
</div>
</form>
</body>


</html>


On Jan 19, 9:33 pm, Jonathan Ellis <jbel...@gmail.com> wrote:
> try with r635.
>
> if that doesn't work, please post the html that the form is rendering as.
>
> -Jonathan
>

Jonathan ellis

unread,
Jan 20, 2009, 8:40:53 AM1/20/09
to forma...@googlegroups.com
R635 is the latest svn.

-Jonathan

On Jan 20, 2009, at 7:29 AM, ballparkfh <fdhe...@yahoo.com> wrote:

>
> Again, I apologize, but I don't know what r635 is.
>
> Here is the html the create form is rendering.
>
>
> <html>
> <head>
> <style media="screen" type="text/css"><!-- @import url(/admin/
> static_contents/admin.css); --></style>
>
>
>
>
> </head>
> <div>
> <a href="/admin">

ballparkfh

unread,
Jan 20, 2009, 8:43:01 AM1/20/09
to FormAlchemy
I figured out what you meant by r635. I checked out the latest, and
tried it, and I'm getting the same error.

On Jan 20, 7:29 am, ballparkfh <fdhen...@yahoo.com> wrote:
> Again, I apologize, but I don't know what r635 is.
>
> Here is the html the create form is rendering.
>
> <html>
> <head>
> <style media="screen" type="text/css"><!-- @import url(/admin/
> static_contents/admin.css); --></style>
>
> </head>
> <div>
>   <a href="/admin">

ballparkfh

unread,
Jan 20, 2009, 8:36:49 PM1/20/09
to FormAlchemy
Hi Jonathan, I don't know if you saw my last post because we posted
at around the same time, but r635 didn't fix the problem.

Thanks,
Frank
> > > >> - Show quoted text -- Hide quoted text -

Jonathan Ellis

unread,
Jan 20, 2009, 10:17:27 PM1/20/09
to forma...@googlegroups.com
Okay, you should be good to go in 636.  Sorry it took so long to track down.

-Jonathan

ballparkfh

unread,
Jan 21, 2009, 6:53:02 AM1/21/09
to FormAlchemy
Awesome! Looks great! Thanks so much.

On Jan 20, 9:17 pm, Jonathan Ellis <jbel...@gmail.com> wrote:
> Okay, you should be good to go in 636.  Sorry it took so long to track down.
> -Jonathan
>

ballparkfh

unread,
Jan 21, 2009, 9:58:31 AM1/21/09
to FormAlchemy
Hi Jonathan,

I'm sorry to have to open this up again. It looks like there is no
way to select None in the drop down for super_task, which means that I
am only able to create a top-level task the first time that I create a
task. Because the super_task_id column is nullable, we should be able
to pick None as a super task. I created a similar model using django,
but as I have told you, django doesn't completely fit my needs, and I
am excited about formalchemy. Anyway, django gives you a "-----" in
the dropdown when the foreign key is nullable. Is this possible to do
in formalchemy?

Thanks again so much,
Frank

Jonathan ellis

unread,
Jan 22, 2009, 9:29:52 AM1/22/09
to forma...@googlegroups.com
I can't think of a good way to do this off the top of my head, but I
agree that it's important. Please add an issue to the tracker.

-Jonathan
Reply all
Reply to author
Forward
0 new messages