Michael Bayer wrote:
> On Jul 18, 2006, at 5:54 PM, Randall Smith wrote:
>
>
>>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?
>>
>
>
> yup. you need to post a fully working test case (strongly preferred:
> sqlite, single .py file) since i cannot reproduce this error in
> similar setups.
>
I'll give the test a shot tomorrow. It happens within the TurboGears
framework. Here's a snip showing how TG connects:
import sqlalchemy
from sqlalchemy.ext import activemapper, sessioncontext
def get_engine():
"Retreives the engine based on the current configuration"
global _engine
if not _engine:
dburi = config.get("sqlalchemy.dburi")
if not dburi:
raise KeyError("No sqlalchemy database config found!")
_engine = sqlalchemy.create_engine(dburi)
metadata.connect(_engine)
elif not metadata.is_bound():
metadata.connect(_engine)
return _engine
def create_session():
"Creates a session with the appropriate engine"
return sqlalchemy.create_session(bind_to=get_engine())
metadata = activemapper.metadata
session = activemapper.Objectstore(create_session)
activemapper.objectstore = session
After pasting that, I feel like I should be posting in TG. Anyway, I'm
guessing the problem may have to do with how I connect. I'm grabbing
the session from where it is defined above. So my session actions look
like this:
from turbogears.database import session as tg_session
# class stuff
def doSomething(self, sqla_object):
tg_session.delete(sqla_object)
# TG issues flush at end of request.
# If I issue is manually here it makes no difference.
BTW, It works if I change the code to this:
def doSomething(self, sqla_object):
docid = sqla_object.id
session = create_session(bind_to=get_engine())
##objectstore.delete(sqla_object)
document = session.query(Document).get(docid)
session.delete(document)
session.flush()
session.close()
But this defeats the purpose of receiving an sqla object and the TG
connection scheme.
So I don't think it's a problem with my model, but rather with the
connection scheme. Again, I'll try to make something reproducible tomorrow.
Thanks.
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users