me and my now ex-girlfriend just broke...
sorry, couldn't help myself. it's just that I've been the whole
afternoon chasing this bug in #sqlalchemy. see the attached script. it
basically creates a Feed and a Post related with that Feed. the Feed
goes just fine in the db, but the Post goes with a NULL feed_id[1].
until yesterday did worked, but seems like after I upgraded to the
new sqla 0.4.2-1 from Debian Sid, it broke this way. am I doing anything
conceptually wrong?
--
$ sqlite3 test.sqlt
SQLite version 3.4.2
Enter ".help" for instructions
sqlite> select * from post;
1|http://bonga.org/posts/post.html||Fist post!|This the fist post. Like the
fist import, but not.|2008-01-07 00:44:03|read
^^ this is where feed_id should not be NULL!
sqlite> select * from feed;
1|bonga|http://bonga.org/rss.xml|1
--
(Not so) Random fortune:
Cruickshank's Law of Committees: If a committee is allowed to discuss a bad idea
long enough, it will inevitably decide to implement the idea simply because so
much work has already been done on it.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
from sqlalchemy import *
from sqlalchemy.orm import mapper, relation
import mx.DateTime
import sqlalchemy.orm
class SQLAObject (object):
def __init__ (self, **kwargs):
object.__init__ (self)
self.__dict__.update (kwargs)
class Feed (SQLAObject):
pass
class Post (SQLAObject):
pass
def main ():
db= create_engine ('sqlite:///test.sqlt')
meta= MetaData (db)
feeds= Table ('feed', meta,
Column ('id', Integer, primary_key=True),
Column ('name', Unicode, index=True, unique=True),
# Column ('name', Unicode),
Column ('url', TEXT),
Column ('active', BOOLEAN),
)
posts= Table ('post', meta,
Column ('id', Integer, primary_key=True),
Column ('guid', TEXT, index=True, unique=True),
# Column ('guid', TEXT),
Column ('feed_id', Integer, ForeignKey ('feed.id')),
Column ('title', Unicode),
Column ('content', Unicode),
Column ('date', DateTime),
Column ('state', TEXT), # new, unread, later, read, deleted
)
mapper (Feed, feeds, properties=dict (
posts=relation (Post, backref='feed'),
))
mapper (Post, posts)
# create databases, for the first run
try:
meta.create_all (checkfirst=True)
except exceptions.InvalidRequestError:
meta= BoundMetaData (db)
# meta.create_all (checkfirst=True)
meta.create_all (checkfirst=False)
session= sqlalchemy.orm.create_session (bind=db)
feed= Feed (name=u'bonga', url='http://bonga.org/rss.xml', active=True)
session.save (feed)
session.flush ()
post= Post (
guid='http://bonga.org/posts/post.html',
feed=feed,
title=u'Fist post!',
content=u'This the fist post. Like the fist import, but not.',
date=mx.DateTime.now (),
state='read'
)
session.save (post)
session.flush ()
session.close ()
if __name__=='__main__':
main ()
# end