> stack trace you posted doesn't make sense to me though, as its issuing
> a SELECT statement but PG is raising an exception for an UPDATE /
> DELETE ? I've never seen that before. If you can provide a self-
> contained test case which reproduces that behavior we can try it out.
Here is is. The behaviuor is as explained both on pg8.2 and 8.3. The
error is raised only if ForeignKey has initially='DEFERRED' (or the database
has that even if the SA definition does not.
sandro
*:-)
--------------------------------------------------------------------------
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, ForeignKey, text, func
from sqlalchemy.orm import relation, scoped_session, sessionmaker
from sqlalchemy.types import *
import sqlalchemy
Base = declarative_base()
Base.metadata.bind = "postgres://localhost/sa4"
meta = Base.metadata
Session = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=meta.bind))
session = Session()
class Project(Base):
__tablename__ = 'ticket_project'
id = Column(Integer, primary_key=True)
name = Column(String(20))
class Report(Base):
__tablename__ = 'timereport_report'
id = Column(Integer, primary_key=True)
job_id = Column('job_id',
ForeignKey(Project.id,
deferrable=True, initially='DEFERRED'), nullable=False)
def populate():
meta.create_all()
p1 = Project(name='TestPrj')
session.add(p1)
session.commit()
p1 = session.query(Project).filter_by(name='TestPrj').one()
r1= Report(job_id=p1.id)
session.add(r1)
session.commit()
def delete():
global p1
p1 = session.query(Project).filter_by(name='TestPrj').one()
session.delete(p1)
try:
session.commit()
except Exception, e:
print e
session.rollback()
populate()
delete()
print p1.name
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
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
-~----------~----~----~----~------~----~------~--~---