thats weird, inserting None into a PK col, even for mysql, should  
fail.  try a small standalone test script that just INSERTs blank  
PK's into tables and see if it raises errors.


On Jan 11, 2007, at 8:36 PM, Chris Shenton wrote:

>
> I've noticed this a few times now.  Due to faulty logic in my code, or
> a misunderstanding of the constraints in my schema, I create a record
> through the ORM, then save() and flush() it but it doesn't get put in
> the DB. This is frequently due to me setting an attribute None which
> has a Nullable=False constraint.
>
> But what's buggin' me is that it fails silently.  I don't know there
> was a problem inserting the record.  For example, I have this table:
>
> fault_table =
>     Table('fault', metadata,
>           Column('fault_id',          Integer,         
> primary_key=True),
>           Column('system_id',         Integer,        ForeignKey 
> ('system.system_id'), nullable=False),
>           Column('faulttrack_id',     Integer,        ForeignKey 
> ('faulttrack.faulttrack_id'), nullable=True), # initially empty
>           Column('msgpath',           String,         nullable=False),
>           Column('subject',           String,         nullable=False),
>           Column('ts_created',        DateTime,        
> default=func.current_timestamp()),
>           Column('ts_updated',        DateTime,        
> onupdate=func.current_timestamp()),
>           )
>
>
> If I inadvertently set a system_id to None (as below) the insert
> doesn't work but no exception is thrown nor error logged:
>
>         fault2 = Fault(system_id = None, # this violates the no- 
> NULL restriction
>                        msgpath = '/dev/null/UNSAVEDFAULT',
>                        subject = 'UNSAVED FAULT',
>                        )
>         self.session.save(fault2)
>         self.session.flush()
>
> I turned on Echo so I could see the SQL, and everything looks fine,
> but nothing is stored and no error is reported:
>
>   2007-01-11 20:30:38,922 INFO sqlalchemy.engine.base.Engine.0x..4c  
> BEGIN
>   INFO:base: BEGIN
>   2007-01-11 20:30:38,930 INFO sqlalchemy.engine.base.Engine.0x..4c  
> SELECT current_timestamp
>   INFO:base: SELECT current_timestamp
>   2007-01-11 20:30:38,930 INFO sqlalchemy.engine.base.Engine.0x..4c []
>   INFO:base: []
>   2007-01-11 20:30:38,934 INFO sqlalchemy.engine.base.Engine.0x..4c  
> INSERT INTO fault (system_id, faulttrack_id, msgpath, subject,  
> ts_created, ts_updated) VALUES (%s, %s, %s, %s, %s, %s)
>   INFO:base: INSERT INTO fault (system_id, faulttrack_id, msgpath,  
> subject, ts_created, ts_updated) VALUES (%s, %s, %s, %s, %s, %s)
>   2007-01-11 20:30:38,935 INFO sqlalchemy.engine.base.Engine.0x..4c  
> [None, None, '/dev/null/UNSAVEDFAULT', 'UNSAVED FAULT',  
> datetime.datetime(2007, 1, 11, 20, 30, 37), None]
>   INFO:base: [None, None, '/dev/null/UNSAVEDFAULT', 'UNSAVED  
> FAULT', datetime.datetime(2007, 1, 11, 20, 30, 37), None]
>   2007-01-11 20:30:38,940 INFO sqlalchemy.engine.base.Engine.0x..4c  
> COMMIT
>   INFO:base: COMMIT
>
>
> So how do I detect that I'm trying to insert data that will not be
> saved?  Or is there some other work around I'm not aware of?
>
> I'm using MySQL if it makes any difference, and have noticed this both
> under Pylons and from a stand-alone python app like the one above.
>
> Thanks.
>
> >


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to