SQLAlchemy 0.9 Documentation

Release: 0.9.1 | Release Date: January 5, 2014
SQLAlchemy 0.9 Documentation » Changes and Migration » 0.9 Changelog

0.9 Changelog

0.9 Changelog

0.9.1

Released: January 5, 2014

orm

  • [orm] [feature] [extensions] A new, experimental extension sqlalchemy.ext.automap is added. This extension expands upon the functionality of Declarative as well as the DeferredReflection class to produce a base class which automatically generates mapped classes and relationships based on table metadata.

    (link)

  • [orm] [bug] [events] Fixed regression where using a functools.partial() with the event system would cause a recursion overflow due to usage of inspect.getargspec() on it in order to detect a legacy calling signature for certain events, and apparently there’s no way to do this with a partial object. Instead we skip the legacy check and assume the modern style; the check itself now only occurs for the SessionEvents.after_bulk_update and SessionEvents.after_bulk_delete events. Those two events will require the new signature style if assigned to a “partial” event listener.(link)

    References: #2905

  • [orm] [bug] Fixed bug where using new Session.info attribute would fail if the .info argument were only passed to the sessionmaker creation call but not to the object itself. Courtesy Robin Schoonover.(link)

    References: pull request bitbucket:9

  • [orm] [bug] Fixed regression where we don’t check the given name against the correct string class when setting up a backref based on a name, therefore causing the error “too many values to unpack”. This was related to the Py3k conversion.(link)

    References: #2901

  • [orm] [bug] Fixed regression where we apparently still create an implicit alias when saying query(B).join(B.cs), where “C” is a joined inh class; however, this implicit alias was created only considering the immediate left side, and not a longer chain of joins along different joined-inh subclasses of the same base. As long as we’re still implicitly aliasing in this case, the behavior is dialed back a bit so that it will alias the right side in a wider variety of cases.(link)

    References: #2903

orm declarative

  • [bug] [orm] [declarative] Fixed an extremely unlikely memory issue where when using DeferredReflection to define classes pending for reflection, if some subset of those classes were discarded before the DeferredReflection.prepare() method were called to reflect and map the class, a strong reference to the class would remain held within the declarative internals. This internal collection of “classes to map” now uses weak references against the classes themselves.(link)

  • [bug] [orm] [declarative] A quasi-regression where apparently in 0.8 you can set a class-level attribute on declarative to simply refer directly to an InstrumentedAttribute on a superclass or on the class itself, and it acts more or less like a synonym; in 0.9, this fails to set up enough bookkeeping to keep up with the more liberalized backref logic from #2789. Even though this use case was never directly considered, it is now detected by declarative at the “setattr()” level as well as when setting up a subclass, and the mirrored/renamed attribute is now set up as a synonym() instead.(link)

    References: #2900

sql

  • [sql] [feature] Conjunctions like and_() and or_() can now accept Python generators as a single argument, e.g.:

    and_(x == y for x, y in tuples)

    The logic here looks for a single argument *args where the first element is an instance of types.GeneratorType.

    (link)

schema

0.9.0

Released: December 30, 2013

orm

  • [orm] [feature] The exc.StatementError or DBAPI-related subclass now can accomodate additional information about the “reason” for the exception; the Session now adds some detail to it when the exception occurs within an autoflush. This approach is taken as opposed to combining FlushError with a Python 3 style “chained exception” approach so as to maintain compatibility both with Py2K code as well as code that already catches IntegrityError or similar.(link)

  • [orm] [feature] [backrefs] Added new argument include_backrefs=True to the validates() function; when set to False, a validation event will not be triggered if the event was initated as a backref to an attribute operation from the other side.

    (link)

    References: #1535

  • [orm] [feature] A new API for specifying the FOR UPDATE clause of a SELECT is added with the new Query.with_for_update() method, to complement the new GenerativeSelect.with_for_update() method. Pull request courtesy Mario Lassnig.

    (link)

    References: pull request github:42

  • [orm] [bug] An adjustment to the subqueryload() strategy which ensures that the query runs after the loading process has begun; this is so that the subqueryload takes precedence over other loaders that may be hitting the same attribute due to other eager/noload situations at the wrong time.(link)

    This change is also backported to: 0.8.5

    References: #2887

  • [orm] [bug] Fixed bug when using joined table inheritance from a table to a select/alias on the base, where the PK columns were also not same named; the persistence system would fail to copy primary key values from the base table to the inherited table upon INSERT.(link)

    This change is also backported to: 0.8.5

    References: #2885

  • [orm] [bug] composite() will raise an informative error message when the columns/attribute (names) passed don’t resolve to a Column or mapped attribute (such as an erroneous tuple); previously raised an unbound local.(link)

    This change is also backported to: 0.8.5

    References: #2889

  • [orm] [bug] Fixed a regression introduced by #2818 where the EXISTS query being generated would produce a “columns being replaced” warning for a statement with two same-named columns, as the internal SELECT wouldn’t have use_labels set.(link)

    This change is also backported to: 0.8.4

    References: #2818

  • [orm] [bug] [collections] [py3k] Added support for the Python 3 method list.clear() within the ORM collection instrumentation system; pull request courtesy Eduardo Schettino.(link)

    References: pull request github:40

  • [orm] [bug] Some refinements to the AliasedClass construct with regards to descriptors, like hybrids, synonyms, composites, user-defined descriptors, etc. The attribute adaptation which goes on has been made more robust, such that if a descriptor returns another instrumented attribute, rather than a compound SQL expression element, the operation will still proceed. Addtionally, the “adapted” operator will retain its class; previously, a change in class from InstrumentedAttribute to QueryableAttribute (a superclass) would interact with Python’s operator system such that an expression like aliased(MyClass.x) > MyClass.x would reverse itself to read myclass.x < myclass_1.x. The adapted attribute will also refer to the new AliasedClass as its parent which was not always the case before.(link)

    References: #2872

  • [orm] [bug] The viewonly flag on relationship() will now prevent attribute history from being written on behalf of the target attribute. This has the effect of the object not being written to the Session.dirty list if it is mutated. Previously, the object would be present in Session.dirty, but no change would take place on behalf of the modified attribute during flush. The attribute still emits events such as backref events and user-defined events and will still receive mutations from backrefs.

    (link)

    References: #2833

  • [orm] [bug] Added support for new Session.info attribute to scoped_session.(link)

  • [orm] [bug] Fixed bug where usage of new Bundle object would cause the Query.column_descriptions attribute to fail.(link)

  • [orm] [bug] [sqlite] [sql] Fixed a regression introduced by the join rewriting feature of #2369 and #2587 where a nested join with one side already an aliased select would fail to translate the ON clause on the outside correctly; in the ORM this could be seen when using a SELECT statement as a “secondary” table.(link)

    References: #2858

orm declarative

  • [bug] [orm] [declarative] Declarative does an extra check to detect if the same Column is mapped multiple times under different properties (which typically should be a synonym() instead) or if two or more Column objects are given the same name, raising a warning if this condition is detected.(link)

    References: #2828

  • [bug] [orm] [declarative] The DeferredReflection class has been enhanced to provide automatic reflection support for the “secondary” table referred to by a relationship(). “secondary”, when specified either as a string table name, or as a Table object with only a name and MetaData object will also be included in the reflection process when DeferredReflection.prepare() is called.(link)

    References: #2865

  • [bug] [orm] [declarative] Fixed bug where in Py2K a unicode literal would not be accepted as the string name of a class or other argument within declarative using relationship().(link)

engine

  • [engine] [feature] The engine_from_config() function has been improved so that we will be able to parse dialect-specific arguments from string configuration dictionaries. Dialect classes can now provide their own list of parameter types and string-conversion routines. The feature is not yet used by the built-in dialects, however.(link)

    References: #2875

  • [engine] [bug] A DBAPI that raises an error on connect() which is not a subclass of dbapi.Error (such as TypeError, NotImplementedError, etc.) will propagate the exception unchanged. Previously, the error handling specific to the connect() routine would both inappropriately run the exception through the dialect’s Dialect.is_disconnect() routine as well as wrap it in a sqlalchemy.exc.DBAPIError. It is now propagated unchanged in the same way as occurs within the execute process.(link)

    This change is also backported to: 0.8.4

    References: #2881

  • [engine] [bug] [pool] The QueuePool has been enhanced to not block new connection attempts when an existing connection attempt is blocking. Previously, the production of new connections was serialized within the block that monitored overflow; the overflow counter is now altered within it’s own critical section outside of the connection process itself.(link)

    This change is also backported to: 0.8.4

    References: #2880

  • [engine] [bug] [pool] Made a slight adjustment to the logic which waits for a pooled connection to be available, such that for a connection pool with no timeout specified, it will every half a second break out of the wait to check for the so-called “abort” flag, which allows the waiter to break out in case the whole connection pool was dumped; normally the waiter should break out due to a notify_all() but it’s possible this notify_all() is missed in very slim cases. This is an extension of logic first introduced in 0.8.0, and the issue has only been observed occasionally in stress tests.(link)

    This change is also backported to: 0.8.4

    References: #2522

  • [engine] [bug] Fixed bug where SQL statement would be improperly ASCII-encoded when a pre-DBAPI StatementError were raised within Connection.execute(), causing encoding errors for non-ASCII statements. The stringification now remains within Python unicode thus avoiding encoding errors.(link)

    This change is also backported to: 0.8.4

    References: #2871

  • [engine] [bug] The create_engine() routine and the related make_url() function no longer considers the + sign to be a space within the password field. The parsing has been adjuted to match RFC 1738 exactly, in that both username and password expect only :, @, and / to be encoded.

    (link)

    References: #2873

  • [engine] [bug] The RowProxy object is now sortable in Python as a regular tuple is; this is accomplished via ensuring tuple() conversion on both sides within the __eq__() method as well as the addition of a __lt__() method.

    (link)

    References: #2848

sql

  • [sql] [feature] New improvements to the text() construct, including more flexible ways to set up bound parameters and return types; in particular, a text() can now be turned into a full FROM-object, embeddable in other statements as an alias or CTE using the new method TextClause.columns(). The text() construct can also render “inline” bound parameters when the construct is compiled in a “literal bound” context.

    (link)

    References: #2882, #2877

  • [sql] [feature] A new API for specifying the FOR UPDATE clause of a SELECT is added with the new GenerativeSelect.with_for_update() method. This method supports a more straightforward system of setting dialect-specific options compared to the for_update keyword argument of select(), and also includes support for the SQL standard FOR UPDATE OF clause. The ORM also includes a new corresponding method Query.with_for_update(). Pull request courtesy Mario Lassnig.

    (link)

    References: pull request github:42

  • [sql] [feature] The precision used when coercing a returned floating point value to Python Decimal via string is now configurable. The flag decimal_return_scale is now supported by all Numeric and Float types, which will ensure this many digits are taken from the native floating point value when it is converted to string. If not present, the type will make use of the value of .scale, if the type supports this setting and it is non-None. Otherwise the original default length of 10 is used.

    (link)

    References: #2867

  • [sql] [bug] Fixed issue where a primary key column that has a Sequence on it, yet the column is not the “auto increment” column, either because it has a foreign key constraint or autoincrement=False set, would attempt to fire the Sequence on INSERT for backends that don’t support sequences, when presented with an INSERT missing the primary key value. This would take place on non-sequence backends like SQLite, MySQL.(link)

    This change is also backported to: 0.8.5

    References: #2896

  • [sql] [bug] Fixed bug with Insert.from_select() method where the order of the given names would not be taken into account when generating the INSERT statement, thus producing a mismatch versus the column names in the given SELECT statement. Also noted that Insert.from_select() implies that Python-side insert defaults cannot be used, since the statement has no VALUES clause.(link)

    This change is also backported to: 0.8.5

    References: #2895

  • [sql] [bug] The cast() function, when given a plain literal value, will now apply the given type to the given literal value on the bind parameter side according to the type given to the cast, in the same manner as that of the type_coerce() function. However unlike type_coerce(), this only takes effect if a non-clauseelement value is passed to cast(); an existing typed construct will retain its type.(link)

  • [sql] [bug] The ForeignKey class more aggressively checks the given column argument. If not a string, it checks that the object is at least a ColumnClause, or an object that resolves to one, and that the .table attribute, if present, refers to a TableClause or subclass, and not something like an Alias. Otherwise, a ArgumentError is raised.(link)

    References: #2883

  • [sql] [bug] The precedence rules for the ColumnOperators.collate() operator have been modified, such that the COLLATE operator is now of lower precedence than the comparison operators. This has the effect that a COLLATE applied to a comparison will not render parenthesis around the comparison, which is not parsed by backends such as MSSQL. The change is backwards incompatible for those setups that were working around the issue by applying Operators.collate() to an individual element of the comparison expression, rather than the comparison expression as a whole.(link)

    References: #2879

  • [sql] [enhancement] The exception raised when a BindParameter is present in a compiled statement without a value now includes the key name of the bound parameter in the error message.(link)

    This change is also backported to: 0.8.5

schema

  • [schema] [bug] Fixed a regression caused by #2812 where the repr() for table and column names would fail if the name contained non-ascii characters.(link)

    References: #2868

postgresql

  • [postgresql] [feature] Support for Postgresql JSON has been added, using the new JSON type. Huge thanks to Nathan Rice for implementing and testing this.(link)

    References: #2581, pull request github:50

  • [postgresql] [feature] Added support for Postgresql TSVECTOR via the postgresql.TSVECTOR type. Pull request courtesy Noufal Ibrahim.(link)

    References: pull request bitbucket:8

  • [postgresql] [bug] Fixed bug where index reflection would mis-interpret indkey values when using the pypostgresql adapter, which returns these values as lists vs. psycopg2’s return type of string.(link)

    This change is also backported to: 0.8.4

    References: #2855

  • [postgresql] [bug] Now using psycopg2 UNICODEARRAY extension for handling unicode arrays with psycopg2 + normal “native unicode” mode, in the same way the UNICODE extension is used.(link)

  • [postgresql] [bug] Fixed bug where values within an ENUM weren’t escaped for single quote signs. Note that this is backwards-incompatible for existing workarounds that manually escape the single quotes.

    (link)

    References: #2878

mysql

  • [mysql] [bug] Improvements to the system by which SQL types generate within __repr__(), particularly with regards to the MySQL integer/numeric/ character types which feature a wide variety of keyword arguments. The __repr__() is important for use with Alembic autogenerate for when Python code is rendered in a migration script.(link)

    References: #2893

mssql

  • [mssql] [bug] [firebird] The “asdecimal” flag used with the Float type will now work with Firebird as well as the mssql+pyodbc dialects; previously the decimal conversion was not occurring.(link)

    This change is also backported to: 0.8.5

  • [mssql] [bug] [pymssql] Added “Net-Lib error during Connection reset by peer” message to the list of messages checked for “disconnect” within the pymssql dialect. Courtesy John Anderson.(link)

    This change is also backported to: 0.8.5

    References: pull request github:51

  • [mssql] [bug] Fixed bug introduced in 0.8.0 where the DROP INDEX statement for an index in MSSQL would render incorrectly if the index were in an alternate schema; the schemaname/tablename would be reversed. The format has been also been revised to match current MSSQL documentation. Courtesy Derek Harland.(link)

    This change is also backported to: 0.8.4

    References: pull request bitbucket:7

oracle

  • [oracle] [bug] Added ORA-02396 “maximum idle time” error code to list of “is disconnect” codes with cx_oracle.(link)

    This change is also backported to: 0.8.4

    References: #2864

  • [oracle] [bug] Fixed bug where Oracle VARCHAR types given with no length (e.g. for a CAST or similar) would incorrectly render None CHAR or similar.(link)

    This change is also backported to: 0.8.4

    References: #2870

firebird

  • [firebird] [bug] The firebird dialect will quote identifiers which begin with an underscore. Courtesy Treeve Jelbert.(link)

    This change is also backported to: 0.8.5

    References: #2897

  • [firebird] [bug] Fixed bug in Firebird index reflection where the columns within the index were not sorted correctly; they are now sorted in order of RDB$FIELD_POSITION.(link)

    This change is also backported to: 0.8.5

  • [firebird] [bug] Changed the queries used by Firebird to list table and view names to query from the rdb$relations view instead of the rdb$relation_fields and rdb$view_relations views. Variants of both the old and new queries are mentioned on many FAQ and blogs, however the new queries are taken straight from the “Firebird FAQ” which appears to be the most official source of info.(link)

    References: #2898

misc

  • [bug] [declarative] Error message when a string arg sent to relationship() which doesn’t resolve to a class or mapper has been corrected to work the same way as when a non-string arg is received, which indicates the name of the relationship which had the configurational error.(link)

    This change is also backported to: 0.8.5

    References: #2888

  • [bug] [ext] Fixed bug which prevented the serializer extension from working correctly with table or column names that contain non-ASCII characters.(link)

    This change is also backported to: 0.8.4

    References: #2869

  • [bug] [examples] Fixed bug which prevented history_meta recipe from working with joined inheritance schemes more than one level deep.(link)

  • [removed] The “informix” and “informixdb” dialects have been removed; the code is now available as a separate repository on Bitbucket. The IBM-DB project has provided production-level Informix support since the informixdb dialect was first added.(link)

0.9.0b1

Released: October 26, 2013

general

  • [general] [feature] [py3k] The C extensions are ported to Python 3 and will build under any supported CPython 2 or 3 environment.(link)

    References: #2161

  • [general] [feature] [py3k] The codebase is now “in-place” for Python 2 and 3, the need to run 2to3 has been removed. Compatibility is now against Python 2.6 on forward.(link)

    References: #2671

  • [general] A large refactoring of packages has reorganized the import structure of many Core modules as well as some aspects of the ORM modules. In particular sqlalchemy.sql has been broken out into several more modules than before so that the very large size of sqlalchemy.sql.expression is now pared down. The effort has focused on a large reduction in import cycles. Additionally, the system of API functions in sqlalchemy.sql.expression and sqlalchemy.orm has been reorganized to eliminate redundancy in documentation between the functions vs. the objects they produce.(link)

orm

  • [orm] [feature] Added new option to relationship() distinct_target_key. This enables the subquery eager loader strategy to apply a DISTINCT to the innermost SELECT subquery, to assist in the case where duplicate rows are generated by the innermost query which corresponds to this relationship (there’s not yet a general solution to the issue of dupe rows within subquery eager loading, however, when joins outside of the innermost subquery produce dupes). When the flag is set to True, the DISTINCT is rendered unconditionally, and when it is set to None, DISTINCT is rendered if the innermost relationship targets columns that do not comprise a full primary key. The option defaults to False in 0.8 (e.g. off by default in all cases), None in 0.9 (e.g. automatic by default). Thanks to Alexander Koval for help with this.

    (link)

    This change is also backported to: 0.8.3

    References: #2836

  • [orm] [feature] The association proxy now returns None when fetching a scalar attribute off of a scalar relationship, where the scalar relationship itself points to None, instead of raising an AttributeError.

    (link)

    References: #2810

  • [orm] [feature] Added new method AttributeState.load_history(), works like AttributeState.history but also fires loader callables.

    (link)

    References: #2787

  • [orm] [feature] Added a new load option orm.load_only(). This allows a series of column names to be specified as loading “only” those attributes, deferring the rest.(link)

    References: #1418

  • [orm] [feature] The system of loader options has been entirely rearchitected to build upon a much more comprehensive base, the Load object. This base allows any common loader option like joinedload(), defer(), etc. to be used in a “chained” style for the purpose of specifying options down a path, such as joinedload("foo").subqueryload("bar"). The new system supersedes the usage of dot-separated path names, multiple attributes within options, and the usage of _all() options.

    (link)

    References: #1418

  • [orm] [feature] The composite() construct now maintains the return object when used in a column-oriented Query, rather than expanding out into individual columns. This makes use of the new Bundle feature internally. This behavior is backwards incompatible; to select from a composite column which will expand out, use MyClass.some_composite.clauses.

    (link)

    References: #2824

  • [orm] [feature] A new construct Bundle is added, which allows for specification of groups of column expressions to a Query construct. The group of columns are returned as a single tuple by default. The behavior of Bundle can be overridden however to provide any sort of result processing to the returned row. The behavior of Bundle is also embedded into composite attributes now when they are used in a column-oriented Query.

    (link)

    References: #2824

  • [orm] [feature] The version_id_generator parameter of Mapper can now be specified to rely upon server generated version identifiers, using triggers or other database-provided versioning features, or via an optional programmatic value, by setting version_id_generator=False. When using a server-generated version identfier, the ORM will use RETURNING when available to immediately load the new version value, else it will emit a second SELECT.(link)

    References: #2793

  • [orm] [feature] The eager_defaults flag of Mapper will now allow the newly generated default values to be fetched using an inline RETURNING clause, rather than a second SELECT statement, for backends that support RETURNING.(link)

    References: #2793

  • [orm] [feature] Added a new attribute Session.info to Session; this is a dictionary where applications can store arbitrary data local to a Session. The contents of Session.info can be also be initialized using the info argument of Session or sessionmaker.(link)

  • [orm] [feature] Removal of event listeners is now implemented. The feature is provided via the event.remove() function.

    (link)

    References: #2268

  • [orm] [feature] The mechanism by which attribute events pass along an AttributeImpl as an “initiator” token has been changed; the object is now an event-specific object called attributes.Event. Additionally, the attribute system no longer halts events based on a matching “initiator” token; this logic has been moved to be specific to ORM backref event handlers, which are the typical source of the re-propagation of an attribute event onto subsequent append/set/remove operations. End user code which emulates the behavior of backrefs must now ensure that recursive event propagation schemes are halted, if the scheme does not use the backref handlers. Using this new system, backref handlers can now peform a “two-hop” operation when an object is appended to a collection, associated with a new many-to-one, de-associated with the previous many-to-one, and then removed from a previous collection. Before this change, the last step of removal from the previous collection would not occur.

    (link)

    References: #2789

  • [orm] [feature] A major change regarding how the ORM constructs joins where the right side is itself a join or left outer join. The ORM is now configured to allow simple nesting of joins of the form a JOIN (b JOIN c ON b.id=c.id) ON a.id=b.id, rather than forcing the right side into a SELECT subquery. This should allow significant performance improvements on most backends, most particularly MySQL. The one database backend that has for many years held back this change, SQLite, is now addressed by moving the production of the SELECT subquery from the ORM to the SQL compiler; so that a right-nested join on SQLite will still ultimately render with a SELECT, while all other backends are no longer impacted by this workaround.

    As part of this change, a new argument flat=True has been added to the orm.aliased(), Join.alias(), and orm.with_polymorphic() functions, which allows an “alias” of a JOIN to be produced which applies an anonymous alias to each component table within the join, rather than producing a subquery.

    (link)

    References: #2587

  • [orm] [bug] Fixed bug where using an annotation such as remote() or foreign() on a Column before association with a parent Table could produce issues related to the parent table not rendering within joins, due to the inherent copy operation performed by an annotation.(link)

    This change is also backported to: 0.8.3

    References: #2813

  • [orm] [bug] Fixed bug where Query.exists() failed to work correctly without any WHERE criterion. Courtesy Vladimir Magamedov.(link)

    This change is also backported to: 0.8.3

    References: #2818

  • [orm] [bug] Fixed a potential issue in an ordered sequence implementation used by the ORM to iterate mapper hierarchies; under the Jython interpreter this implementation wasn’t ordered, even though cPython and Pypy maintained ordering.(link)

    This change is also backported to: 0.8.3

    References: #2794

  • [orm] [bug] Fixed bug in ORM-level event registration where the “raw” or “propagate” flags could potentially be mis-configured in some “unmapped base class” configurations.(link)

    This change is also backported to: 0.8.3

    References: #2786

  • [orm] [bug] A performance fix related to the usage of the defer() option when loading mapped entities. The function overhead of applying a per-object deferred callable to an instance at load time was significantly higher than that of just loading the data from the row (note that defer() is meant to reduce DB/network overhead, not necessarily function call count); the function call overhead is now less than that of loading data from the column in all cases. There is also a reduction in the number of “lazy callable” objects created per load from N (total deferred values in the result) to 1 (total number of deferred cols).(link)

    This change is also backported to: 0.8.3

    References: #2778

  • [orm] [bug] Fixed bug whereby attribute history functions would fail when an object we moved from “persistent” to “pending” using the make_transient() function, for operations involving collection-based backrefs.(link)

    This change is also backported to: 0.8.3

    References: #2773

  • [orm] [bug] A warning is emitted when trying to flush an object of an inherited class where the polymorphic discriminator has been assigned to a value that is invalid for the class.(link)

    This change is also backported to: 0.8.2

    References: #2750

  • [orm] [bug] Fixed bug in polymorphic SQL generation where multiple joined-inheritance entities against the same base class joined to each other as well would not track columns on the base table independently of each other if the string of joins were more than two entities long.(link)

    This change is also backported to: 0.8.2

    References: #2759

  • [orm] [bug] Fixed bug where sending a composite attribute into Query.order_by() would produce a parenthesized expression not accepted by some databases.(link)

    This change is also backported to: 0.8.2

    References: #2754

  • [orm] [bug] Fixed the interaction between composite attributes and the aliased() function. Previously, composite attributes wouldn’t work correctly in comparison operations when aliasing was applied.(link)

    This change is also backported to: 0.8.2

    References: #2755

  • [orm] [bug] [ext] Fixed bug where MutableDict didn’t report a change event when clear() was called.(link)

    This change is also backported to: 0.8.2

    References: #2730

  • [orm] [bug] Fixed bug where list instrumentation would fail to represent a setslice of [0:0] correctly, which in particular could occur when using insert(0, item) with the association proxy. Due to some quirk in Python collections, the issue was much more likely with Python 3 rather than 2.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2807

  • [orm] [bug] attributes.get_history() when used with a scalar column-mapped attribute will now honor the “passive” flag passed to it; as this defaults to PASSIVE_OFF, the function will by default query the database if the value is not present. This is a behavioral change vs. 0.8.

    (link)

    References: #2787

  • [orm] [bug] [associationproxy] Added additional criterion to the ==, != comparators, used with scalar values, for comparisons to None to also take into account the association record itself being non-present, in addition to the existing test for the scalar endpoint on the association record being NULL. Previously, comparing Cls.scalar == None would return records for which Cls.associated were present and Cls.associated.scalar is None, but not rows for which Cls.associated is non-present. More significantly, the inverse operation Cls.scalar != None would return Cls rows for which Cls.associated was non-present.

    The case for Cls.scalar != 'somevalue' is also modified to act more like a direct SQL comparison; only rows for which Cls.associated is present and Associated.scalar is non-NULL and not equal to 'somevalue' are returned. Previously, this would be a simple NOT EXISTS.

    Also added a special use case where you can call Cls.scalar.has() with no arguments, when Cls.scalar is a column-based value - this returns whether or not Cls.associated has any rows present, regardless of whether or not Cls.associated.scalar is NULL or not.

    (link)

    References: #2751

  • [orm] [bug] Fixed an obscure bug where the wrong results would be fetched when joining/joinedloading across a many-to-many relationship to a single-table-inheriting subclass with a specific discriminator value, due to “secondary” rows that would come back. The “secondary” and right-side tables are now inner joined inside of parenthesis for all ORM joins on many-to-many relationships so that the left->right join can accurately filtered. This change was made possible by finally addressing the issue with right-nested joins outlined in #2587.

    (link)

    References: #2369

  • [orm] [bug] The “auto-aliasing” behavior of the Query.select_from() method has been turned off. The specific behavior is now availble via a new method Query.select_entity_from(). The auto-aliasing behavior here was never well documented and is generally not what’s desired, as Query.select_from() has become more oriented towards controlling how a JOIN is rendered. Query.select_entity_from() will also be made available in 0.8 so that applications which rely on the auto-aliasing can shift their applications to use this method.

    (link)

    References: #2736

orm declarative

  • [feature] [orm] [declarative] Added a convenience class decorator as_declarative(), is a wrapper for declarative_base() which allows an existing base class to be applied using a nifty class-decorated approach.(link)

    This change is also backported to: 0.8.3

  • [feature] [orm] [declarative] ORM descriptors such as hybrid properties can now be referenced by name in a string argument used with order_by, primaryjoin, or similar in relationship(), in addition to column-bound attributes.(link)

    This change is also backported to: 0.8.2

    References: #2761

engine

  • [engine] [feature] repr() for the URL of an Engine will now conceal the password using asterisks. Courtesy Gunnlaugur Þór Briem.(link)

    This change is also backported to: 0.8.3

    References: #2821

  • [engine] [feature] New events added to ConnectionEvents:

    (link)

    References: #2770

  • [engine] [bug] [oracle] Dialect.initialize() is not called a second time if an Engine is recreated, due to a disconnect error. This fixes a particular issue in the Oracle 8 dialect, but in general the dialect.initialize() phase should only be once per dialect.(link)

    This change is also backported to: 0.8.3

    References: #2776

  • [engine] [bug] [pool] Fixed bug where QueuePool would lose the correct checked out count if an existing pooled connection failed to reconnect after an invalidate or recycle event.(link)

    This change is also backported to: 0.8.3

    References: #2772

  • [engine] [bug] Fixed bug where the reset_on_return argument to various Pool implementations would not be propagated when the pool was regenerated. Courtesy Eevee.(link)

    This change is also backported to: 0.8.2

    References: pull request github:6

  • [engine] [bug] The regexp used by the make_url() function now parses ipv6 addresses, e.g. surrounded by brackets.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2851

  • [engine] [bug] The method signature of Dialect.reflecttable(), which in all known cases is provided by DefaultDialect, has been tightened to expect include_columns and exclude_columns arguments without any kw option, reducing ambiguity - previously exclude_columns was missing.(link)

    References: #2748

sql

  • [sql] [feature] Added support for “unique constraint” reflection, via the Inspector.get_unique_constraints() method. Thanks for Roman Podolyaka for the patch.(link)

    This change is also backported to: 0.8.4

    References: #1443

  • [sql] [feature] The update(), insert(), and delete() constructs will now interpret ORM entities as target tables to be operated upon, e.g.:

    from sqlalchemy import insert, update, delete
    
    ins = insert(SomeMappedClass).values(x=5)
    
    del_ = delete(SomeMappedClass).where(SomeMappedClass.id == 5)
    
    upd = update(SomeMappedClass).where(SomeMappedClass.id == 5).values(name='ed')
    (link)

    This change is also backported to: 0.8.3

  • [sql] [feature] [postgresql] [mysql] The Postgresql and MySQL dialects now support reflection/inspection of foreign key options, including ON UPDATE, ON DELETE. Postgresql also reflects MATCH, DEFERRABLE, and INITIALLY. Coutesy ijl.(link)

    References: #2183

  • [sql] [feature] A bindparam() construct with a “null” type (e.g. no type specified) is now copied when used in a typed expression, and the new copy is assigned the actual type of the compared column. Previously, this logic would occur on the given bindparam() in place. Additionally, a similar process now occurs for bindparam() constructs passed to ValuesBase.values() for an Insert or Update construct, within the compilation phase of the construct.

    These are both subtle behavioral changes which may impact some usages.

    (link)

    References: #2850

  • [sql] [feature] An overhaul of expression handling for special symbols particularly with conjunctions, e.g. None expression.null() expression.true() expression.false(), including consistency in rendering NULL in conjunctions, “short-circuiting” of and_() and or_() expressions which contain boolean constants, and rendering of boolean constants and expressions as compared to “1” or “0” for backends that don’t feature true/false constants.

    (link)

    References: #2734, #2804, #2823

  • [sql] [feature] The typing system now handles the task of rendering “literal bind” values, e.g. values that are normally bound parameters but due to context must be rendered as strings, typically within DDL constructs such as CHECK constraints and indexes (note that “literal bind” values become used by DDL as of #2742). A new method TypeEngine.literal_processor() serves as the base, and TypeDecorator.process_literal_param() is added to allow wrapping of a native literal rendering method.

    (link)

    References: #2838

  • [sql] [feature] The Table.tometadata() method now produces copies of all SchemaItem.info dictionaries from all SchemaItem objects within the structure including columns, constraints, foreign keys, etc. As these dictionaries are copies, they are independent of the original dictionary. Previously, only the .info dictionary of Column was transferred within this operation, and it was only linked in place, not copied.(link)

    References: #2716

  • [sql] [feature] The default argument of Column now accepts a class or object method as an argument, in addition to a standalone function; will properly detect if the “context” argument is accepted or not.(link)

  • [sql] [feature] Added new method to the insert() construct Insert.from_select(). Given a list of columns and a selectable, renders INSERT INTO (table) (columns) SELECT ... While this feature is highlighted as part of 0.9 it is also backported to 0.8.3.

    (link)

    References: #722

  • [sql] [feature] Provided a new attribute for TypeDecorator called TypeDecorator.coerce_to_is_types, to make it easier to control how comparisons using == or != to None and boolean types goes about producing an IS expression, or a plain equality expression with a bound parameter.(link)

    References: #2734, #2744

  • [sql] [feature] A label() construct will now render as its name alone in an ORDER BY clause, if that label is also referred to in the columns clause of the select, instead of rewriting the full expression. This gives the database a better chance to optimize the evaulation of the same expression in two different contexts.

    (link)

    References: #1068

  • [sql] [bug] Fixed bug where type_coerce() would not interpret ORM elements with a __clause_element__() method properly.(link)

    This change is also backported to: 0.8.3

    References: #2849

  • [sql] [bug] The Enum and Boolean types now bypass any custom (e.g. TypeDecorator) type in use when producing the CHECK constraint for the “non native” type. This so that the custom type isn’t involved in the expression within the CHECK, since this expression is against the “impl” value and not the “decorated” value.(link)

    This change is also backported to: 0.8.3

    References: #2842

  • [sql] [bug] The .unique flag on Index could be produced as None if it was generated from a Column that didn’t specify unique (where it defaults to None). The flag will now always be True or False.(link)

    This change is also backported to: 0.8.3

    References: #2825

  • [sql] [bug] Fixed bug in default compiler plus those of postgresql, mysql, and mssql to ensure that any literal SQL expression values are rendered directly as literals, instead of as bound parameters, within a CREATE INDEX statement. This also changes the rendering scheme for other DDL such as constraints.(link)

    This change is also backported to: 0.8.3

    References: #2742

  • [sql] [bug] A select() that is made to refer to itself in its FROM clause, typically via in-place mutation, will raise an informative error message rather than causing a recursion overflow.(link)

    This change is also backported to: 0.8.3

    References: #2815

  • [sql] [bug] Fixed bug where using the column_reflect event to change the .key of the incoming Column would prevent primary key constraints, indexes, and foreign key constraints from being correctly reflected.(link)

    This change is also backported to: 0.8.3

    References: #2811

  • [sql] [bug] The ColumnOperators.notin_() operator added in 0.8 now properly produces the negation of the expression “IN” returns when used against an empty collection.(link)

    This change is also backported to: 0.8.3

  • [sql] [bug] [postgresql] Fixed bug where the expression system relied upon the str() form of a some expressions when referring to the .c collection on a select() construct, but the str() form isn’t available since the element relies on dialect-specific compilation constructs, notably the __getitem__() operator as used with a Postgresql ARRAY element. The fix also adds a new exception class UnsupportedCompilationError which is raised in those cases where a compiler is asked to compile something it doesn’t know how to.(link)

    This change is also backported to: 0.8.3

    References: #2780

  • [sql] [bug] Multiple fixes to the correlation behavior of Select constructs, first introduced in 0.8.0:

    • To satisfy the use case where FROM entries should be correlated outwards to a SELECT that encloses another, which then encloses this one, correlation now works across multiple levels when explicit correlation is established via Select.correlate(), provided that the target select is somewhere along the chain contained by a WHERE/ORDER BY/columns clause, not just nested FROM clauses. This makes Select.correlate() act more compatibly to that of 0.7 again while still maintaining the new “smart” correlation.
    • When explicit correlation is not used, the usual “implicit” correlation limits its behavior to just the immediate enclosing SELECT, to maximize compatibility with 0.7 applications, and also prevents correlation across nested FROMs in this case, maintaining compatibility with 0.8.0/0.8.1.
    • The Select.correlate_except() method was not preventing the given FROM clauses from correlation in all cases, and also would cause FROM clauses to be incorrectly omitted entirely (more like what 0.7 would do), this has been fixed.
    • Calling select.correlate_except(None) will enter all FROM clauses into correlation as would be expected.
    (link)

    This change is also backported to: 0.8.2

    References: #2668, #2746

  • [sql] [bug] Fixed bug whereby joining a select() of a table “A” with multiple foreign key paths to a table “B”, to that table “B”, would fail to produce the “ambiguous join condition” error that would be reported if you join table “A” directly to “B”; it would instead produce a join condition with multiple criteria.(link)

    This change is also backported to: 0.8.2

    References: #2738

  • [sql] [bug] [reflection] Fixed bug whereby using MetaData.reflect() across a remote schema as well as a local schema could produce wrong results in the case where both schemas had a table of the same name.(link)

    This change is also backported to: 0.8.2

    References: #2728

  • [sql] [bug] Removed the “not implemented” __iter__() call from the base ColumnOperators class, while this was introduced in 0.8.0 to prevent an endless, memory-growing loop when one also implements a __getitem__() method on a custom operator and then calls erroneously list() on that object, it had the effect of causing column elements to report that they were in fact iterable types which then throw an error when you try to iterate. There’s no real way to have both sides here so we stick with Python best practices. Careful with implementing __getitem__() on your custom operators!(link)

    This change is also backported to: 0.8.2

    References: #2726

  • [sql] [bug] Fixed regression dating back to 0.7.9 whereby the name of a CTE might not be properly quoted if it was referred to in multiple FROM clauses.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2801

  • [sql] [bug] [cte] Fixed bug in common table expression system where if the CTE were used only as an alias() construct, it would not render using the WITH keyword.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2783

  • [sql] [bug] Fixed bug in CheckConstraint DDL where the “quote” flag from a Column object would not be propagated.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2784

  • [sql] [bug] The “name” attribute is set on Index before the “attach” events are called, so that attachment events can be used to dynamically generate a name for the index based on the parent table and/or columns.(link)

    References: #2835

  • [sql] [bug] The erroneous kw arg “schema” has been removed from the ForeignKey object. this was an accidental commit that did nothing; a warning is raised in 0.8.3 when this kw arg is used.(link)

    References: #2831

  • [sql] [bug] A rework to the way that “quoted” identifiers are handled, in that instead of relying upon various quote=True flags being passed around, these flags are converted into rich string objects with quoting information included at the point at which they are passed to common schema constructs like Table, Column, etc. This solves the issue of various methods that don’t correctly honor the “quote” flag such as Engine.has_table() and related methods. The quoted_name object is a string subclass that can also be used explicitly if needed; the object will hold onto the quoting preferences passed and will also bypass the “name normalization” performed by dialects that standardize on uppercase symbols, such as Oracle, Firebird and DB2. The upshot is that the “uppercase” backends can now work with force-quoted names, such as lowercase-quoted names and new reserved words.

    (link)

    References: #2812

  • [sql] [bug] The resolution of ForeignKey objects to their target Column has been reworked to be as immediate as possible, based on the moment that the target Column is associated with the same MetaData as this ForeignKey, rather than waiting for the first time a join is constructed, or similar. This along with other improvements allows earlier detection of some foreign key configuration issues. Also included here is a rework of the type-propagation system, so that it should be reliable now to set the type as None on any Column that refers to another via ForeignKey - the type will be copied from the target column as soon as that other column is associated, and now works for composite foreign keys as well.

    (link)

    References: #1765

postgresql

  • [postgresql] [feature] Support for Postgresql 9.2 range types has been added. Currently, no type translation is provided, so works directly with strings or psycopg2 2.5 range extension types at the moment. Patch courtesy Chris Withers.(link)

    This change is also backported to: 0.8.2

  • [postgresql] [feature] Added support for “AUTOCOMMIT” isolation when using the psycopg2 DBAPI. The keyword is available via the isolation_level execution option. Patch courtesy Roman Podolyaka.(link)

    This change is also backported to: 0.8.2

    References: #2072

  • [postgresql] [feature] Added support for rendering SMALLSERIAL when a SmallInteger type is used on a primary key autoincrement column, based on server version detection of Postgresql version 9.2 or greater.(link)

    References: #2840

  • [postgresql] [bug] Removed a 128-character truncation from the reflection of the server default for a column; this code was original from PG system views which truncated the string for readability.(link)

    This change is also backported to: 0.8.3

    References: #2844

  • [postgresql] [bug] Parenthesis will be applied to a compound SQL expression as rendered in the column list of a CREATE INDEX statement.(link)

    This change is also backported to: 0.8.3

    References: #2742

  • [postgresql] [bug] Fixed bug where Postgresql version strings that had a prefix preceding the words “Postgresql” or “EnterpriseDB” would not parse. Courtesy Scott Schaefer.(link)

    This change is also backported to: 0.8.3

    References: #2819

  • [postgresql] [bug] The behavior of extract() has been simplified on the Postgresql dialect to no longer inject a hardcoded ::timestamp or similar cast into the given expression, as this interfered with types such as timezone-aware datetimes, but also does not appear to be at all necessary with modern versions of psycopg2.(link)

    This change is also backported to: 0.8.2

    References: #2740

  • [postgresql] [bug] Fixed bug in HSTORE type where keys/values that contained backslashed quotes would not be escaped correctly when using the “non native” (i.e. non-psycopg2) means of translating HSTORE data. Patch courtesy Ryan Kelly.(link)

    This change is also backported to: 0.8.2

    References: #2766

  • [postgresql] [bug] Fixed bug where the order of columns in a multi-column Postgresql index would be reflected in the wrong order. Courtesy Roman Podolyaka.(link)

    This change is also backported to: 0.8.2

    References: #2767

mysql

  • [mysql] [feature] The mysql_length parameter used with Index can now be passed as a dictionary of column names/lengths, for use with composite indexes. Big thanks to Roman Podolyaka for the patch.(link)

    This change is also backported to: 0.8.2

    References: #2704

  • [mysql] [feature] The MySQL mysql.SET type now features the same auto-quoting behavior as that of mysql.ENUM. Quotes are not required when setting up the value, but quotes that are present will be auto-detected along with a warning. This also helps with Alembic where the SET type doesn’t render with quotes.(link)

    References: #2817

  • [mysql] [bug] The change in #2721, which is that the deferrable keyword of ForeignKeyConstraint is silently ignored on the MySQL backend, will be reverted as of 0.9; this keyword will now render again, raising errors on MySQL as it is not understood - the same behavior will also apply to the initially keyword. In 0.8, the keywords will remain ignored but a warning is emitted. Additionally, the match keyword now raises a CompileError on 0.9 and emits a warning on 0.8; this keyword is not only silently ignored by MySQL but also breaks the ON UPDATE/ON DELETE options.

    To use a ForeignKeyConstraint that does not render or renders differently on MySQL, use a custom compilation option. An example of this usage has been added to the documentation, see MySQL Foreign Key Options.

    (link)

    This change is also backported to: 0.8.3

    References: #2721, #2839

  • [mysql] [bug] MySQL-connector dialect now allows options in the create_engine query string to override those defaults set up in the connect, including “buffered” and “raise_on_warnings”.(link)

    This change is also backported to: 0.8.3

    References: #2515

  • [mysql] [bug] Fixed bug when using multi-table UPDATE where a supplemental table is a SELECT with its own bound parameters, where the positioning of the bound parameters would be reversed versus the statement itself when using MySQL’s special syntax.(link)

    This change is also backported to: 0.8.2

    References: #2768

  • [mysql] [bug] Added another conditional to the mysql+gaerdbms dialect to detect so-called “development” mode, where we should use the rdbms_mysqldb DBAPI. Patch courtesy Brett Slatkin.(link)

    This change is also backported to: 0.8.2

    References: #2715

  • [mysql] [bug] The deferrable keyword argument on ForeignKey and ForeignKeyConstraint will not render the DEFERRABLE keyword on the MySQL dialect. For a long time we left this in place because a non-deferrable foreign key would act very differently than a deferrable one, but some environments just disable FKs on MySQL, so we’ll be less opinionated here.(link)

    This change is also backported to: 0.8.2

    References: #2721

  • [mysql] [bug] Updates to MySQL reserved words for versions 5.5, 5.6, courtesy Hanno Schlichting.(link)

    This change is also backported to: 0.8.3, 0.7.11

    References: #2791

  • [mysql] [bug] Fix and test parsing of MySQL foreign key options within reflection; this complements the work in #2183 where we begin to support reflection of foreign key options such as ON UPDATE/ON DELETE cascade.(link)

    References: #2839

  • [mysql] [bug] Improved support for the cymysql driver, supporting version 0.6.5, courtesy Hajime Nakagami.(link)

sqlite

  • [sqlite] [bug] The newly added SQLite DATETIME arguments storage_format and regexp apparently were not fully implemented correctly; while the arguments were accepted, in practice they would have no effect; this has been fixed.(link)

    This change is also backported to: 0.8.3

    References: #2781

  • [sqlite] [bug] Added sqlalchemy.types.BIGINT to the list of type names that can be reflected by the SQLite dialect; courtesy Russell Stuart.(link)

    This change is also backported to: 0.8.2

    References: #2764

mssql

  • [mssql] [bug] When querying the information schema on SQL Server 2000, removed a CAST call that was added in 0.8.1 to help with driver issues, which apparently is not compatible on 2000. The CAST remains in place for SQL Server 2005 and greater.(link)

    This change is also backported to: 0.8.2

    References: #2747

  • [mssql] [bug] [pyodbc] Fixes to MSSQL with Python 3 + pyodbc, including that statements are passed correctly.(link)

    References: #2355

oracle

  • [oracle] [feature] [py3k] The Oracle unit tests with cx_oracle now pass fully under Python 3.(link)

  • [oracle] [bug] Fixed bug where Oracle table reflection using synonyms would fail if the synonym and the table were in different remote schemas. Patch to fix courtesy Kyle Derr.(link)

    This change is also backported to: 0.8.3

    References: #2853

firebird

  • [firebird] [feature] Added new flag retaining=True to the kinterbasdb and fdb dialects. This controls the value of the retaining flag sent to the commit() and rollback() methods of the DBAPI connection. Due to historical concerns, this flag defaults to True in 0.8.2, however in 0.9.0b1 this flag defaults to False.(link)

    This change is also backported to: 0.8.2

    References: #2763

  • [firebird] [feature] The fdb dialect is now the default dialect when specified without a dialect qualifier, i.e. firebird://, per the Firebird project publishing fdb as their official Python driver.(link)

    References: #2504

  • [firebird] [bug] Type lookup when reflecting the Firebird types LONG and INT64 has been fixed so that LONG is treated as INTEGER, INT64 treated as BIGINT, unless the type has a “precision” in which case it’s treated as NUMERIC. Patch courtesy Russell Stuart.(link)

    This change is also backported to: 0.8.2

    References: #2757

misc

  • [feature] Added a new flag system=True to Column, which marks the column as a “system” column which is automatically made present by the database (such as Postgresql oid or xmin). The column will be omitted from the CREATE TABLE statement but will otherwise be available for querying. In addition, the CreateColumn construct can be appled to a custom compilation rule which allows skipping of columns, by producing a rule that returns None.(link)

    This change is also backported to: 0.8.3

  • [feature] [examples] Improved the examples in examples/generic_associations, including that discriminator_on_association.py makes use of single table inheritance do the work with the “discriminator”. Also added a true “generic foreign key” example, which works similarly to other popular frameworks in that it uses an open-ended integer to point to any other table, foregoing traditional referential integrity. While we don’t recommend this pattern, information wants to be free.(link)

    This change is also backported to: 0.8.3

  • [feature] [core] Added a new variant to UpdateBase.returning() called ValuesBase.return_defaults(); this allows arbitrary columns to be added to the RETURNING clause of the statement without interfering with the compilers usual “implicit returning” feature, which is used to efficiently fetch newly generated primary key values. For supporting backends, a dictionary of all fetched values is present at ResultProxy.returned_defaults.(link)

    References: #2793

  • [feature] [pool] Added pool logging for “rollback-on-return” and the less used “commit-on-return”. This is enabled with the rest of pool “debug” logging.(link)

    References: #2752

  • [bug] [examples] Added “autoincrement=False” to the history table created in the versioning example, as this table shouldn’t have autoinc on it in any case, courtesy Patrick Schmid.(link)

    This change is also backported to: 0.8.3

  • [bug] [ext] Fixed bug whereby if a composite type were set up with a function instead of a class, the mutable extension would trip up when it tried to check that column for being a MutableComposite (which it isn’t). Courtesy asldevi.(link)

    This change is also backported to: 0.8.2

  • [bug] [examples] Fixed an issue with the “versioning” recipe whereby a many-to-one reference could produce a meaningless version for the target, even though it was not changed, when backrefs were present. Patch courtesy Matt Chisholm.(link)

    This change is also backported to: 0.8.2

  • [requirements] The Python mock library is now required in order to run the unit test suite. While part of the standard library as of Python 3.3, previous Python installations will need to install this in order to run unit tests or to use the sqlalchemy.testing package for external dialects.(link)

    This change is also backported to: 0.8.2