I'm having trouble compiling my mappers. What I'm doing is a sort of image
board thingy, and trying to model it via sqlalchemy. I'm using postgresql. My
database is like this:
(page down for the rest of my question)
-------------------8<----------------------------------------------
users = Table('users', metadata,
Column('id',Integer,primary_key=True),
Column('uname',String(16),unique=True),
Column('nym',String(32)),
Column('description',TEXT),
Column('interests', TEXT),
Column('password', Binary),
Column('link', TEXT),
Column('picture', TEXT),
Column('ContactInfo', TEXT),
Column('email',TEXT),
Column('PageSize',Integer,PassiveDefault('50')),
Column('visited',DateTime),
schema='identity'
)
posts = Table('posts',metadata,
Column('id',Integer,primary_key=True),
Column('parent',Integer,ForeignKey('chan.posts.id'),index=True),
Column('subject',String(128)),
Column('message',TEXT),
Column('created',DateTime),
Column('ChildAdded',DateTime),
Column('frozen',Boolean,PassiveDefault('0')),
Column('link',TEXT),
Column('image',PickleType),
Column('artist',TEXT),
Column('poster',Integer,ForeignKey('identity.users.id'),nullable=False),
schema='chan')
channels = Table('channels',metadata,
Column('name',String(128),primary_key=True),
Column('top',Integer, ForeignKey('posts.id')),
Column('description',TEXT),
schema='chan')
seen = Table('seen',metadata,
Column('uid',Integer,ForeignKey('identity.users.id'),primary_key=True),
Column('post',Integer,ForeignKey('chan.posts.id')),
schema='chan')
blablah...create(...)
-------------------8<----------------------------------------------
It's an overcomplicated setup I admit, but the database seems to swallow all
that stuff pretty smoothly during creation. The problem comes when I try to do
a simple mapping to one of the types. It seems like an intermittent error that
always seems to hit one of the types. I can't detect any rhyme or reason,
sadly. What I'll do is something like this:
-------------------8<----------------------------------------------
class User(object):
def _get_password(...):
...
return self._password_hash
def set_password(...):
...
password = property(_get_password,set_password
...
table = Table('users',metadata,autoload=True,schema='identity')
usermap = mapper(User,table,properties={
'_password_hash': table.c.password
})
table = Table('posts',metadata,...schema='chan')
postmap = mapper(Post,...)
etc...
usermap.compile()
-------------------8<----------------------------------------------
At that point, everything goes all to Hell. Not literally of course. I get
errors like:
File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 712, in
corresponding_column
for c in column.orig_set:
AttributeError: type object 'User' has no attribute 'orig_set'
or:
File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 712, in
corresponding_column
for c in column.orig_set:
AttributeError: type object 'Post' has no attribute 'orig_set'
...during that usermap.compile() stage. Is there any reason that User wouldn't
be construed as a ColumnElement? Is there any reason the framework would
mistakenly think User to be a ColumnElement when it shouldn't? Is there any
reason those errors should come up, then disappear, leaving other mysterious
errors ("SQL Invalid syntax, at FROM"???) to boggle my brain?
The specific code for the mapping is...here:
http://synx.us.to/code/fib/channel/handler.py
Do a text search for the 'Mappers' class. Each type has its own @classmethod
called 'mapper' which I then call so that I can closely couple the
properties={} clause with the class itself. So respectively there are 4
functions that all call sqlalchemy.mapper (or as I put it, db.mapper)
3 in here:
http://synx.us.to/code/fib/channel/__init__.py
And 1 in here:
http://synx.us.to/code/fib/identity/user.py
Again, do a text search for 'mapper' in those files to find the mapper
functions.
Is there a problem with me using the cls variable in the classmethod to map?
Would that mean a later query somewhere else like session.query(user.User)
would not work because it's not 'cls'? Is it a problem if I pass the sqlalchemy
module as an argument, instead of importing it explicitly in each of the 4
files? Why would the compile() stage fail, in any case?
--
Mongoose
jabber: http://synx.us.to/jabber.png
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users