I'm getting unexpected behavior when deleting a record with a foreign 
key.  I'm using the 0.2.5 rev 1712.  When I delete a record that has a 
private=True attribute in the FK relationship, SA tries to update the 
record and set the FK to NULL instead of deleting the record.

Applicable code.  I tried not to include too much code below.

*******************************************************************************
documents = Table('documents', metadata,
     Column('id', INTEGER, primary_key=True),
     Column('project_id', INTEGER,
         ForeignKey(projects.c.id), nullable=False),
     Column('efile_record_id', INTEGER, nullable=False),
     Column('notes', TEXT),
     Column('input_time', TIMESTAMP, timestamp_default, nullable=False),
     schema=schemaname
)

class Document(object):
     pass

mapper(Document, documents,
     properties={'project':relation(Project, backref='documents', 
private=True)}
)

# Some other code in another module ...

session.delete(document)
session.flush()
*******************************************************************************

Here is the error:

SQLError: (IntegrityError) null value in column "project_id" violates 
not-null constraint
  'UPDATE planreview.documents SET project_id=%(project_id)s WHERE 
documents.id = %(documents_id)s' {'project_id': None, 'documents_id': 13}

Shouldn't this be a delete statement?

Randall


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to