I don't really understand that test since its calling first() on a nonexistent 
InviteCode (the table is empty), and seems to be testing something about an 
IntegrityError on a completely different table so I can't really see what it is 
you're trying to achieve.

Below is a test case that includes only the key features of your test that seem 
like they're relevant.   Please modify this test case to show me how you get 
the erroneous behavior.   

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

e = create_engine('sqlite://', echo=True)

Base = declarative_base()

class InviteCode(Base):
    __tablename__ = 'invite_codes'
    id = Column(Integer, primary_key=True)
    used = Column(Integer, default=0)
    users = relationship("User", backref="invite_code")

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    invite_code_id = Column(Integer, ForeignKey('invite_codes.id'))
    email = Column(String, unique=True)

Base.metadata.create_all(e)

session = Session(e, autocommit=True)

invite_code = InviteCode()
session.add(invite_code)
session.flush()

assert invite_code.used == 0

session.close()

invite_code = session.query(InviteCode).first()

invite_code.used = invite_code.used + 1

session.begin()
user_row = User(
                email="sam...@email.com",
                invite_code_id=None)
session.commit()

assert invite_code.used == 1



On Jan 9, 2011, at 8:58 PM, Romy wrote:

> On Jan 9, 1:48 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> Still not seeing how that would make a difference if that's fully what's 
>> going on.  What is the value of "invite_code.used" after the assignment ?   
>> Does loading "invite_code.used" change the result of the output ?  Can you 
>> test "assert invite_code in elixir.session" ?
> 
> If I insert print statements before and after the assignment, it shows
> that it correctly increments invite_code.used by 1. So, if before is 1
> after is 2, etc. Not sure what you meant by loading invite_code.used,
> but I was printing it after the assignment (and it prints the
> correctly updated value). assert invite_code in elixir.session is True
> 
> Here's a link [http://linux.ucla.edu/~bsack/dbtest.tgz] to a self-
> contained test that requires elixir and a single row in the
> invite_codes table, and produces the following output on my machine:
> 
> r...@dev-01:~$ ./dbtest.py
> elixir: 0.7.1
> sqlalchemy: 0.6.4
> {'code': '1234567', 'email': 'a...@b.com', 'used': 8L, 'created_by_id':
> 30L, 'total': 1L, 'id': 1L}
> before: 8
> after: 9
> Email already in use. Rolling back.
> 
> 
> Afterwards, the database used value stays updated at 9, and will get
> incremented every time I run.
> 
> Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to