- the last_inserted_ids() method has been renamed to the
descriptor "inserted_primary_key".
+ - the Binary type now returns data as a Python string
+ (or a "bytes" type in Python 3), instead of the built-
+ in "buffer" type. This allows symmetric round trips
+ of binary data. [ticket:1524]
+
- User-defined "default" and "onupdate" callables which
accept a context should now call upon
"context.current_parameters" to get at the dictionary
eq_([A(b=5), B(e=7)], session.query(A).all())
+class BinaryHistTest(_base.MappedTest, testing.AssertsExecutionResults):
+ @classmethod
+ def define_tables(cls, metadata):
+ Table('t1', metadata,
+ Column('id', sa.Integer, primary_key=True),
+ Column('data', sa.Binary),
+ )
+
+ @classmethod
+ def setup_classes(cls):
+ class Foo(_base.BasicEntity):
+ pass
+ @testing.resolve_artifact_names
+ def test_binary_equality(self):
+
+ mapper(Foo, t1)
+
+ s = create_session()
+
+ f1 = Foo(data="this is some data")
+ s.add(f1)
+ s.flush()
+ s.expire_all()
+ f1 = s.query(Foo).first()
+ assert f1.data == "this is some data"
+ f1.data = "this is some data"
+ eq_(
+ sa.orm.attributes.get_history(f1, "data"),
+ ((), ["this is some data"], ())
+ )
+ def go():
+ s.flush()
+ self.assert_sql_count(testing.db, go, 0)
+
class MutableTypesTest(_base.MappedTest):
@classmethod
for stmt in (
binary_table.select(order_by=binary_table.c.primary_id),
- text("select * from binary_table order by binary_table.primary_id", typemap={'pickled':PickleType, 'mypickle':MyPickleType}, bind=testing.db)
+ text(
+ "select * from binary_table order by binary_table.primary_id",
+ typemap={'pickled':PickleType, 'mypickle':MyPickleType, 'data':Binary, 'data_slice':Binary},
+ bind=testing.db)
):
- eq_data = lambda x, y: eq_(list(x), list(y))
- if util.jython:
- _eq_data = eq_data
- def eq_data(x, y):
- # Jython currently returns arrays
- from array import ArrayType
- if isinstance(y, ArrayType):
- return eq_(x, y.tostring())
- return _eq_data(x, y)
+ #if util.jython:
+ # TODO: may need to modify Binary type directly
+ # to detect jython if something other than str()/bytes()
+ # is needed to convert from raw to string/bytes.
+ # ArrayType should no longer be expected here though.
+ # users who want raw ArrayType can of course create their
+ # own BinaryType that does no conversion.
+ #_eq_data = eq_data
+ #def eq_data(x, y):
+ # # Jython currently returns arrays
+ # from array import ArrayType
+ # if isinstance(y, ArrayType):
+ # return eq_(x, y.tostring())
+ # return _eq_data(x, y)
l = stmt.execute().fetchall()
- eq_data(stream1, l[0]['data'])
- eq_data(stream1[0:100], l[0]['data_slice'])
- eq_data(stream2, l[1]['data'])
+ eq_(stream1, l[0]['data'])
+ eq_(stream1[0:100], l[0]['data_slice'])
+ eq_(stream2, l[1]['data'])
eq_(testobj1, l[0]['pickled'])
eq_(testobj2, l[1]['pickled'])
eq_(testobj3.moredata, l[0]['mypickle'].moredata)