[sqlalchemy] Re: Test data apparently not saving

2007-01-18 Thread Patrick Lewis


After upgrading sqlite to the most recent version (3.3.10), my problem
went away and everything works as expected.

Thanks for the help, and sorry for the noise.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Test data apparently not saving

2007-01-13 Thread Patrick Lewis

I reran the above with a postgres database, and it all worked as
expected.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Test data apparently not saving

2007-01-13 Thread Michael Bayer


then its your sqlite version since it runs fine for me with sqlite.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Test data apparently not saving

2007-01-11 Thread Michael Bayer
OK, i made it into a straight down program (attached) and it  
completes fine.



--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy.ext.sessioncontext import SessionContext

metadata = sa.BoundMetaData('sqlite:///:memory:')
metadata.engine.echo = True

ctx = SessionContext(sa.create_session)

groups_table = sa.Table('tg_group', metadata,
sa.Column('group_id', sa.Integer, primary_key=True),
sa.Column('group_name', sa.Unicode(16), unique=True),
sa.Column('display_name', sa.Unicode(255)),
sa.Column('created', sa.DateTime, default=datetime.now)
)

users_table = sa.Table('tg_user', metadata,
sa.Column('user_id', sa.Integer, primary_key=True),
sa.Column('user_name', sa.Unicode(16), unique=True),
sa.Column('email_address', sa.Unicode(255), unique=True),
sa.Column('display_name', sa.Unicode(255)),
sa.Column('password', sa.Unicode(40)),
sa.Column('created', sa.DateTime, default=datetime.now)
)

user_group_table = sa.Table('user_group', metadata,
sa.Column('user_id', sa.Integer, sa.ForeignKey('tg_user.user_id')),
sa.Column('group_id', sa.Integer, sa.ForeignKey('tg_group.group_id'))
)

class User(object):

def __repr__(self):
return class User user_id=%s email_address=%s display_name=%s % (
self.user_id, self.email_address, self.display_name)

class Group(object):
pass

gmapper = sa.mapper(Group, groups_table)
umapper = sa.mapper(User, users_table, properties=dict(
groups = sa.relation(Group, secondary=user_group_table, backref='users')
)
)


def sa_create(class_, **kw):
try:
obj = class_(**kw)
except TypeError:
obj = class_()
sa_update(obj, **kw) # update takes care of save/flush
return obj

def sa_update(obj, **kw):
[setattr(obj, key, value) for key, value in kw.iteritems()]
push_to_db(obj)

def push_to_db(obj):
had_session = True
session = sa.orm.session.object_session(obj)
if not session:
print Didn't find session
session = ctx.current
had_session = False
session.save(obj)
session.flush((obj,))
if not had_session:
session.expunge(obj)

ctx.current.clear()
session = ctx.current
# Create tables
metadata.drop_all()
metadata.create_all()
user1 = User() 
user1.user_name='bobvilla'
user1.email_address='[EMAIL PROTECTED]'
user1.display_name='Bob Villa'
user1.password='toughasnails'   
session.save(user1)
u2 = User()
u2.user_name='bobathome'
u2.email_address='[EMAIL PROTECTED]'
u2.display_name='Bob Villa'
u2.password='hammertime'
session.save(u2) 
session.flush()
print 'UuUuUuU %s' % user1
user1 = user1
session.clear()


session = ctx.current
u1 = session.query(User).select(User.c.user_name=='bobvilla')
l = session.query(User).select()
print u1
for u in l:
print u
assert u1[0].user_id==user1.user_id
assert u1[0].email_address=='[EMAIL PROTECTED]'
assert len(l) == 2

u = sa_create(User, user_name='bobevans', 
   email_address='[EMAIL PROTECTED]', 
   display_name='Bob Evans',
   password='secretsauce')
assert u.user_name=='bobevans'
assert u.user_id  0





On Jan 11, 2007, at 8:36 PM, Patrick Lewis wrote:



 Michael Bayer wrote:
 you need to attach a test case that doenst have all the generalorm
 dependencies.  also, i looked at this and i dont see why the
 ruledispatch stuff cant be factored out of the test as well since
 none of those functions seem to be called.

 Sorry about that.  I thought I had removed all of those, but obviously
 not. Here is a one file test. I've also stripped out the dispatch
 rules, but left the essential logic.

 http://paste.turbogears.org/paste/831

 As i mentioned before, the test_setup case passes when run by itself,
 but not in combination with the test_create test. test_create always
 seems to pass.


 --~--~-~--~~~---~--~~
  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 sqlalchemy- 
 [EMAIL PROTECTED]
 For more options, visit this group at http://groups.google.com/ 
 group/sqlalchemy?hl=en
 -~--~~~~--~~--~--~---




[sqlalchemy] Re: Test data apparently not saving

2007-01-11 Thread Patrick Lewis

Ok, that works for me, too. But, if I rework it how I think the test
suite is running things, I get the same error.

http://paste.turbogears.org/paste/832


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Test data apparently not saving

2007-01-11 Thread Patrick Lewis

A minor revision (made user1 global)

http://paste.turbogears.org/paste/833


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---