On Aug 18, 3:39 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> Sent from my iPhone
>
> On Aug 18, 2010, at 8:27 AM, Oliver Beattie <oli...@obeattie.com> wrote:
>
>
>
>
>
> > I'm not entirely sure why this is happening… it seems to work for me
> > in nearly all other circumstances so I'm a bit stumped. Basically, I
> > have a declarative table which has a character field as its primary
> > key (it's not an ID which can be returned by the server), yet
> > SQLAlchemy is issuing an INSERT…RETURNING statement for it.
>
> > The scenario that seems to make it happening is like this. I'm trying
> > to create a copy of an existing object, with a new ID. All the
> > attributes on the new object should be pulled from the old object
> > (which I'm doing through use of the iterate_properties iterator along
> > with setattr, getarre calls), apart from this primary key field (name)
> > which is a character field and will be something different. A relation
> > on the "old" object will be updated to point at the created object.
> > When commit() happens, I get an IntegrityError because it's thinking
> > the db will return it the primary key (even though I have explicitly
> > set it on the non-persistant instance).
>
> > Is this a know bug or something I'm doing wrong?
>
> If the primary key is a character field, you have to ensure the attribute is 
> populated before the insert occurs.  Otherwise sqlalchemy assumes the value 
> is created by a generator of some kind such as a column default and issues 
> RETURNING, which is perfectly valid for any type of column, to get the value 
> back.

Thanks for your reply, Michael — the value is being populated (as in,
I am setting the value on the instance before I do session.add()) — is
this what you mean?

>
>
>
>
>
> > --
> > 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 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

-- 
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