>From what I've read these errors are usually solved by
adding use_alter=True and inverse.
It doesn't work for me though.
I have ridiculously many relations between two tables. But that's how it is
and I cannot refactor the model at this point.
This is part of the model right now:
class Project(Entity):
id = Field(String(100), primary_key=True)
workers = OneToMany('User')
client = ManyToOne('User')
creator = ManyToOne('User')
class User(Entity):
username = Field(String(80), primary_key=True)
assigned_project = ManyToOne('Project', use_alter=True,
inverse='user_account')
owned_projects = OneToMany('Project', use_alter=True, inverse='client')
created_projects = OneToMany('Project', inverse='creator')
The problem occurs when you both own and created the project and try to
assign yourself to it:
File "/usr/sbin/admin-web", line 25, in service
Application.service(self)
File "/usr/lib/python2.5/site-packages/smisk/mvc/__init__.py", line 879,
in service
rsp = self._call_leaf_and_handle_model_session(req_args, req_params)
File "/usr/lib/python2.5/site-packages/smisk/mvc/__init__.py", line 706,
in _call_leaf_and_handle_model_session
rsp = self._call_leaf(req_args, req_params)
File "/usr/lib/python2.5/site-packages/smisk/mvc/__init__.py", line 695,
in _call_leaf
return self._leaf_filter(*args, **params)
File "/usr/lib/python2.5/site-packages/smisk/mvc/decorators.py", line 72,
in f
return filter(leaf, *va, **kw)
File "/var/mysite/lib/mysite/admin_web/__init__.py", line 139, in
add_authorized_user_to_rsp
return leaf(*va, **kw)
File "/usr/lib/python2.5/site-packages/smisk/mvc/__init__.py", line 298,
in <lambda>
self._leaf_filter = lambda *va, **kw: filter(self.destination)(*va,
**kw)
File "/usr/lib/python2.5/site-packages/smisk/mvc/decorators.py", line 72,
in f
return filter(leaf, *va, **kw)
File "/var/mysite/lib/mysite/admin_web/__init__.py", line 139, in
add_authorized_user_to_rsp
return leaf(*va, **kw)
File "/usr/lib/python2.5/site-packages/smisk/mvc/routing.py", line 65, in
__call__
return self._call_leaf(*args, **params)
File "/usr/lib/python2.5/site-packages/smisk/mvc/routing.py", line 59, in
_call_leaf
return self.leaf(*args, **params)
File "/var/mysite/lib/smisk117compat.py", line 15, in f
return filter(leaf, *va, **kw)
File "/var/mysite/lib/smisk117compat.py", line 81, in _require
return leaf(*va, **kw)
File "/var/mysite/lib/mysite/admin_web/__init__.py", line 1871, in
assign_project
elixir.session.commit()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/scoping.py", line
98, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/var/lib/python-support/python2.5/sqlalchemy/orm/session.py", line
557, in commit
self.transaction.commit()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/session.py", line
262, in commit
self._prepare_impl()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/session.py", line
246, in _prepare_impl
self.session.flush()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/session.py", line
789, in flush
self.uow.flush(self, objects)
File "/var/lib/python-support/python2.5/sqlalchemy/orm/unitofwork.py",
line 233, in flush
flush_context.execute()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/unitofwork.py",
line 442, in execute
tasks = self._sort_dependencies()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/unitofwork.py",
line 480, in _sort_dependencies
for t in task._sort_circular_dependencies(self,
[self.get_task_by_mapper(i) for i in cycles]):
File "/var/lib/python-support/python2.5/sqlalchemy/orm/unitofwork.py",
line 733, in _sort_circular_dependencies
head = topological.sort_as_tree(tuples, allobjects)
File "/var/lib/python-support/python2.5/sqlalchemy/topological.py", line
59, in sort_as_tree
return _organize_as_tree(_sort(tuples, allitems,
allow_cycles=with_cycles))
File "/var/lib/python-support/python2.5/sqlalchemy/topological.py", line
216, in _sort
raise CircularDependencyError("Circular dependency detected " +
repr(edges) + repr(queue))
CircularDependencyError: Circular dependency detected
[(<sqlalchemy.orm.attributes.InstanceState object at 0xa6fa84c>,
<sqlalchemy.orm.attributes.InstanceState object at 0xa6fadcc>),
(<sqlalchemy.orm.attributes.InstanceState object at 0xa6fadcc>,
<sqlalchemy.orm.attributes.InstanceState object at 0xa5ae3ac>),
(<sqlalchemy.orm.attributes.InstanceState object at 0xa6fadcc>,
<sqlalchemy.orm.attributes.InstanceState object at 0xa6fa84c>)][]
I've tried removing the creator reference and only store a string and had a
property that gets the object through a query but get the same error:
@Property
def creator():
def fget(self):
return User.get_by(username=self.creator_name)
def fset(self, value):
if isinstance(value, User):
self.creator_name = value.name
return locals()
Any ideas on what I can try next?
Thx,
JD
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/U7lP75K9TuEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.