RowProxy and ResultProxy should implement complete standard interfaces
I have been using sqlalchemy core and I have found that in RowProxy and ResultProxy, standard interfaces are implemented (and even recommended), but not totally, confusing users (like me).
Although these interfaces implement some of the methods to treat the results as tuples or dicts, they don't implement the ones that give the actual support for these datatypes.
The implementation of standard basetype interfaces should be done using ABCs: https://docs.python.org/3/library/collections.abc.html
In my case, .get() was the function that I expected to be supported (given the dict access they have) but wasn't working, so I switched to a getattr() call instead.
Comments (4)
-
repo owner -
repo owner also, the ABC just breaks the whole thing. Every time I've tried to do the "right" thing and use ABCs for things, even in much simpler cases than this, they never seem to work. We don't even get a real row back. Below, this fails:
from sqlalchemy import create_engine e = create_engine("sqlite://") r = e.execute("select 1") row = r.first() assert row[0] == 1
why does it fail? I have no idea. If you can look into this for me, that would be great.
-
repo owner - changed milestone to 1.x.xx
-
assigned issue to
- marked as major
-
reporter I would not subclass those ABCs but implement the __*__ methods, if I have some time I will try to debug it a little further.
- Log in to comment
unfortunately these are not standard basetypes. The RowProxy acts like a tuple in some ways and a dictionary in the other.
Here's a simple test case:
it passes. If we apply this patch:
now it fails.