Update test program in the atachment. No I don't agree that this is a fixed bug.
Take an example. You got a mapper, and you want just one row, but you dont't know or don't care how to construct a query that only yields one row (not a very unlikely scenario I might add, actually, quite a common one). With selectone out of question since it raises an exception when having a result-set of two, how do you get just one object from a mapper? Quoting Florian Boesch <[EMAIL PROTECTED]>: > I'm sorry I don't quite get it. There's two different issues at hand. > > #1 No result of selectone was forthcomming. > things todo: either return None or Raise an exception (a more sensible one > please), consensus over what to do will have to ensue. > My vote on this goes with None as it can-be quite an expected result not to > get > something from selectone, wheras I see exceptions more of a way to signify > problems that indicate contractial missbehavior. > > #2 How can selectone return more then one? I mean, selectone *is* the > contract... > > Quoting Robert Leftwich <[EMAIL PROTECTED]>: > > > Florian Boesch wrote: > > > selectone of a mapper does not work anymore. > > > > > > > I think you'll find it is still working, it is just throwing an exception > > when 0 > > *or* > 1 rows are returned, i.e. add one f = Foo() and an > > objectstore.commit() > > and the exception goes away, add a second g = Foo() and the exception is > > thrown > > again as more than 1 row has been returned. > > > > When I saw this over the weekend my first reaction was to think it was a > > problem, but the function is called selectone and the new behaviour does > meet > > that contract, i.e give me one and only one row. However, there is now no > way > > to > > tell if the error was thrown because there were no rows or more than one > row, > > which is often a useful piece of information :-). > > > > So, what do people think- should the current behaviour remain or should it > be > > changed? If the latter should it revert to the original behaviour, return > > None > > when no rows are returned and throw the exception if > 1 are returned or > > something else? > > > > Robert > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > > that extends applications into web and mobile media. Attend the live > webcast > > and join the prime developer group breaking into this new coding territory! > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > > _______________________________________________ > > Sqlalchemy-users mailing list > > Sqlalchemy-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users > > > > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users > >
from sqlalchemy import * engine = create_engine('oracle://dsn=orcl&user=test&password=test') foo = Table('foo', engine, Column('id', Integer, Sequence('foo_seq'), primary_key=True)) class Foo(object): pass foos = mapper(Foo, foo) try: foo.drop() except: pass try: foo.create() except: pass foos.selectone() # should raise a more sensible exception or return None foo.insert().execute() foos.selectone() # ok foo.insert().execute() foos.selectone() # eh.. *one* is my understanding of contract... ''' File "selectone.py", line 13, in ? foos.selectone() File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/mapping/mapper.py", line 496, in selectone raise InvalidRequestError('Multiple rows returned for selectone') sqlalchemy.exceptions.InvalidRequestError: Multiple rows returned for selectone '''