On Dec 3, 2009, at 1:23 PM, Alessandro Dentella wrote:

> Hi,
> 
> I'm stuck with the code below raise FlushError complaining:
> 
>   Traceback (most recent call last):
>     File "<stdin>", line 49, in <module>
>     File "/misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py", 
> line 673, in commit
>       self.transaction.commit()
>     File "/misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py", 
> line 378, in commit
>       self._prepare_impl()
>     File "/misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py", 
> line 362, in _prepare_impl
>       self.session.flush()
>     File "/misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py", 
> line 1356, in flush
>       self._flush(objects)
>     File "/misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py", 
> line 1416, in _flush
>       mapperutil.state_str(state), path))
>   sqlalchemy.orm.exc.FlushError: Instance <Delivery at 0x85cb82c> is an 
> unsaved, pending instance and is an orphan (is not attached to any parent 
> 'Project' instance via that classes' 'deliveries' attribute)
> 
> I don't understand what I should do to fix it.
> 
> What I can't understand is why it is considered an orphan: I *do* set job_id
> on it and it should be enought to build the relation (I *do* need
> delete-orphan).

job_id is not going to be recognized within the SQLA's orphan test, which is 
only looking at object associations.   see the FAQ entry on this.

> 
> Is the only solution to attach an instance (u.job = myjob) or is there
> another solution that doesn't require me to build the instance?

if you want SQLA's delete-orphan capability, that's the only way.  If you want 
to rely upon CASCADE rules in your DB to handle it instead, that's another way 
to go.

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to