版本:1.1.0b2 |发布日期:2016年7月1日

SQLAlchemy 1.1文档


1.0.14 ¶ T0>


发动机¶ T0>

  • [engine] [bug] [postgresql] Fixed bug in cross-schema foreign key reflection in conjunction with the MetaData.schema argument, where a referenced table that is present in the “default” schema would fail since there would be no way to indicate a Table that has “blank” for a schema. 特殊符号schema.BLANK_SCHEMA已被添加为Table.schemaSequence.schema的可用值,表示模式名称应该是即使指定了MetaData.schema,也必须被强制为None


SQL ¶ T0>

  • [sql] [bug] Fixed issue in SQL math negation operator where the type of the expression would no longer be the numeric type of the original. 这会导致类型确定结果集行为的问题。


  • [sql] [bug] Fixed bug whereby the __getstate__ / __setstate__ methods for sqlalchemy.util.Properties were non-working due to the transition in the 1.0 series to __slots__. 这个问题可能会影响一些第三方应用程序。Pull请求Pieter Mulder。


  • [sql] [bug] FromClause.count() is pending deprecation for 1.1. 这个函数使用表中的任意一列,不可靠。对于核心使用,应该优先使用func.count()


  • [sql] [bug] Fixed bug in CTE structure which would cause it to not clone properly when a union was used, as is common in a recursive CTE. 当CTE用于各种ORM上下文(如column_property())时,错误的克隆会导致错误。


  • [sql] [bug] Fixed bug whereby Table.tometadata() would make a duplicate UniqueConstraint for each Column object that featured the unique=True parameter.


杂项¶ T0>

  • [bug] [examples] 修正了examples / vertical / dictlike-polymorphic.py例子中发生的一个回退,它阻止了它的运行。


1.0.13 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed bug in “evaluate” strategy of Query.update() and Query.delete() which would fail to accommodate a bound parameter with a “callable” value, as which occurs when filtering by a many-to-one equality expression along a relationship.


  • [orm] [bug] Fixed bug whereby the event listeners used for backrefs could be inadvertently applied multiple times, when using a deep class inheritance hierarchy in conjunction with mutiple mapper configuration steps.


  • [orm] [bug] Fixed bug whereby passing a text() construct to the Query.group_by() method would raise an error, instead of intepreting the object as a SQL fragment.


  • [orm] [bug] Anonymous labeling is applied to a func construct that is passed to column_property(), so that if the same attribute is referred to as a column expression twice the names are de-duped, thus avoiding “ambiguous column” errors. 之前,需要应用.label(None)才能使名称匿名化。


  • [orm] [bug] Fixed regression appearing in the 1.0 series in ORM loading where the exception raised for an expected column missing would incorrectly be a NoneType error, rather than the expected NoSuchColumnError.


SQL ¶ T0>

  • [sql] [bug] Fixed bug where when using case_sensitive=False with an Engine, the result set would fail to correctly accomodate for duplicate column names in the result set, causing an error when the statement is executed in 1.0, and preventing the “ambiguous column” exception from functioning in 1.1.


  • [sql] [bug] Fixed bug where the negation of an EXISTS expression would not be properly typed as boolean in the result, and also would fail to be anonymously aliased in a SELECT list as is the case with a non-negated EXISTS construct.


  • [sql] [bug] Fixed bug where “unconsumed column names” exception would fail to be raised in the case where Insert.values() were called with a list of parameter mappings, instead of a single mapping of parameters. 请求Athena Yao请求。


的PostgreSQL ¶ T0>

  • [postgresql] [bug] 增加了对错误字符串“SSL错误:解密失败或错误的记录mac”的断开连接检测支持。请求礼物Iuri de Silvio。



  • [mssql] [bug] Fixed bug where by ROW_NUMBER OVER clause applied for OFFSET selects in SQL Server would inappropriately substitute a plain column from the local statement that overlaps with a label name used by the ORDER BY criteria of the statement.


  • [mssql] [bug] [oracle] Fixed regression appearing in the 1.0 series which would cause the Oracle and SQL Server dialects to incorrectly account for result set columns when these dialects would wrap a SELECT in a subquery in order to provide LIMIT/OFFSET behavior, and the original SELECT statement referred to the same column multiple times, such as a column and a label of that same column. This issue is related to #3658 in that when the error occurred, it would also cause a NoneType error, rather than reporting that it couldn’t locate a column.


预言¶ T0>

  • [oracle] [bug] 修复了cx_Oracle连接过程中的错误,当用户,密码或dsn为空时,会导致TypeError。这阻止了对Oracle数据库的外部认证,并阻止了连接到默认的dsn。连接字符串oracle://现在使用操作系统用户名登录到缺省dsn,相当于使用sqlplus连接“/”。


  • [oracle] [bug] Fixed a bug in the result proxy used mainly by Oracle when binary and other LOB types are in play, such that when query / statement caching were used, the type-level result processors, notably that required by the binary type itself but also any other processor, would become lost after the first run of the statement due to it being removed from the cached result metadata.


杂项¶ T0>

  • [bug] [examples] Changed the “directed graph” example to no longer consider integer identifiers of nodes as significant; the “higher” / “lower” references now allow mutual edges in both directions.


  • [bug] [py3k] 修正了“to_list”转换中的错误,其中一个字节对象将变成一个单独的字符列表。这会对使用字节对象的主键上的Query.get()方法产生影响。


1.0.12 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed bug in Session.merge() where an object with a composite primary key that has values for some but not all of the PK fields would emit a SELECT statement leaking the internal NEVER_SET symbol into the query, rather than detecting that this object does not have a searchable primary key and no SELECT should be emitted.


  • [orm] [bug] Fixed regression since 0.9 where the 0.9 style loader options system failed to accommodate for multiple undefer_group() loader options in a single query. 现在,即使对同一实体,也可以考虑多个undefer_group()选项。


发动机¶ T0>

  • [engine] [bug] [mysql] Revisiting #2696, first released in 1.0.10, which attempts to work around Python 2’s lack of exception context reporting by emitting a warning for an exception that was interrupted by a second exception when attempting to roll back the already-failed transaction; this issue continues to occur for MySQL backends in conjunction with a savepoint that gets unexpectedly lost, which then causes a “no such savepoint” error when the rollback is attempted, obscuring what the original condition was.

    这个方法已经被推广到核心“安全重新评估”功能,这个功能发生在ORM和Core的任何地方,在事务被回滚以响应发生的尝试提交的错误,包括由SessionConnection,并发生诸如“RELEASE SAVEPOINT”发生故障等操作。以前,修复只适用于ORM刷新/提交过程中的特定路径;它现在也适用于所有跨国情境管理者。


SQL ¶ T0>

  • [sql] [bug] Fixed issue where the “literal_binds” flag was not propagated for expression.insert(), expression.update() or expression.delete() constructs when compiled to string SQL. 请求提供Tim Tate。

    References: #3643, pull request github:232

  • [sql] [bug] Fixed issue where inadvertent use of the Python __contains__ override with a column expression (e.g. by using 'x' in col) would cause an endless loop in the case of an ARRAY type, as Python defers this to __getitem__ access which never raises for this type. 总的来说,所有使用__contains__现在引发NotImplementedError


  • [sql] [bug] Fixed bug in Table metadata construct which appeared around the 0.9 series where adding columns to a Table that was unpickled would fail to correctly establish the Column within the ‘c’ collection, leading to issues in areas such as ORM configuration. 这可能会影响extend_existing等用例。


的PostgreSQL ¶ T0>

  • [postgresql] [bug] Fixed bug in expression.text() construct where a double-colon expression would not escape properly, e.g. some\:\:expr, as is most commonly required when rendering Postgresql-style CAST expressions.



  • [mssql] [bug] Fixed the syntax of the extract() function when used on MSSQL against a datetime value; the quotes around the keyword are removed. 拉请求Guillaume Doumenc。

    References: #3624, pull request bitbucket:70

  • [mssql] [bug] [firebird] Fixed 1.0 regression where the eager fetch of cursor.rowcount was no longer called for an UPDATE or DELETE statement emitted via plain text or via the text() construct, affecting those drivers that erase cursor.rowcount once the cursor is closed such as SQL Server ODBC and Firebird drivers.


预言¶ T0>

  • [oracle] [bug] [jython] Fixed a small issue in the Jython Oracle compiler involving the rendering of “RETURNING” which allows this currently unsupported/untested dialect to work rudimentally with the 1.0 series. 请求卡洛斯里瓦斯请求。


杂项¶ T0>

  • [bug] [py3k] Fixed bug where some exception re-raise scenarios would attach the exception to itself as the “cause”; while the Python 3 interpreter is OK with this, it could cause endless loops in iPython.


1.0.11 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed regression caused in 1.0.10 by the fix for #3593 where the check added for a polymorphic joinedload from a poly_subclass->class->poly_baseclass connection would fail for the scenario of class->poly_subclass->class.


  • [orm] [bug] Fixed bug where Session.bulk_update_mappings() and related would not bump a version id counter when in use. 这里的经验还是有点粗糙,因为在给定的字典中需要原始的版本ID,并且还没有干净的错误报告。


  • [orm] [bug] Major fixes to the Mapper.eager_defaults flag, this flag would not be honored correctly in the case that multiple UPDATE statements were to be emitted, either as part of a flush or a bulk update operation. 此外,在更新语句中不必要地发送RETURNING。


  • [orm] [bug] Fixed bug where use of the Query.select_from() method would cause a subsequent call to the Query.with_parent() method to fail.


SQL ¶ T0>

  • [sql] [bug] Fixed bug in Update.return_defaults() which would cause all insert-default holding columns not otherwise included in the SET clause (such as primary key cols) to get rendered into the RETURNING even though this is an UPDATE.


MySQL的¶ T0>

  • [mysql] [bug] 调整用于解析MySQL视图的正则表达式,使得我们不再假设反射视图源中存在“ALGORITHM”关键字,因为有些用户报告过在某些Amazon RDS环境中不存在。


  • [mysql] [bug] 为MySQL 5.7添加了新的保留字,包括'generated','optimizer_costs','stored','virtual'。请求礼貌Hanno Schlichting。


杂项¶ T0>

  • [bug] [ext] Further fixes to #3605, pop method on MutableDict, where the “default” argument was not included.


  • [bug] [ext] Fixed bug in baked loader system where the systemwide monkeypatch for setting up baked lazy loaders would interfere with other loader strategies that rely on lazy loading as a fallback, e.g. joined and subquery eager loaders, leading to IndexError exceptions at mapper configuration time.


1.0.10 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed issue where post_update on a many-to-one relationship would fail to emit an UPDATE in the case where the attribute were set to None and not previously loaded.


  • [orm] [bug] Fixed bug which is actually a regression that occurred between versions 0.8.0 and 0.8.1, due #2714. 如果加入的加载的加载需要在“with_polymorphic”也被使用的情况下连接到一个子类绑定关系,那么将无法从正确的实体加入。


  • [orm] [bug] Fixed joinedload bug which would occur when a. the query includes limit/offset criteria that forces a subquery b. the relationship uses “secondary” c. the primaryjoin of the relationship refers to a column that is either not part of the primary key, or is a PK col in a joined-inheritance subclass table that is under a different attribute name than the parent table’s primary key column d. the query defers the columns that are present in the primaryjoin, typically via not being included in load_only(); the necessary column(s) would not be present in the subquery and produce invalid SQL.


  • [orm] [bug] A rare case which occurs when a Session.rollback() fails in the scope of a Session.flush() operation that’s raising an exception, as has been observed in some MySQL SAVEPOINT cases, prevents the original database exception from being observed when it was emitted during flush, but only on Py2K because Py2K does not support exception chaining; on Py3K the originating exception is chained. 作为一种解决方法,在我们继续引发回滚起始异常之前,在这个特定情况下会发出警告,至少显示原始数据库错误的字符串消息。


orm declarative

  • [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 backref() on relationship(). 拉尔请求礼貌Nils Philippsen。


SQL ¶ T0>

  • [sql] [feature] 新增了对UPDATE语句中参数排序的SET子句的支持。通过将preserve_parameter_order标志传递给核心Update结构或者将其添加到Query.update.update_args字典, ORM级别,还将参数本身作为2元组列表传递。感谢Gorka Eguileor的实施和测试。


  • [sql] [bug] Fixed issue within the Insert.from_select() construct whereby the Select construct would have its ._raw_columns collection mutated in-place when compiling the Insert construct, when the target Table has Python-side defaults. 在编译Insert之后,Select构造会独立编译出现错误的列,并且Insert语句本身会在一秒钟后失败由于重复的绑定参数而进行的编译尝试


  • [sql] [bug] [postgresql] Fixed bug where CREATE TABLE with a no-column table, but a constraint such as a CHECK constraint would render an erroneous comma in the definition; this scenario can occur such as with a Postgresql INHERITS table that has no columns of its own.


的PostgreSQL ¶ T0>

  • [postgresql] [bug] Fixed issue where the “FOR UPDATE OF” Postgresql-specific SELECT modifier would fail if the referred table had a schema qualifier; PG needs the schema name to be omitted. 拉请求戴安娜克拉克礼貌。


  • [postgresql] [bug] Fixed bug where some varieties of SQL expression passed to the “where” clause of postgresql.ExcludeConstraint would fail to be accepted correctly. 拉请求礼貌aisch。


  • [postgresql] [bug] Fixed the .python_type attribute of postgresql.INTERVAL to return datetime.timedelta in the same way as that of types.Interval.python_type, rather than raising NotImplementedError.


MySQL的¶ T0>

  • [mysql] [bug] Fixed bug in MySQL reflection where the “fractional sections portion” of the mysql.DATETIME, mysql.TIMESTAMP and mysql.TIME types would be incorrectly placed into the timezone attribute, which is unused by MySQL, instead of the fsp attribute.



  • [mssql] [bug] 将错误“20006:写入服务器失败”添加到pymssql驱动程序的断开连接错误列表中,因为已经发现这会导致连接不可用。¶ T2>


  • [mssql] [bug] A descriptive ValueError is now raised in the event that SQL server returns an invalid date or time format from a DATE or TIME column, rather than failing with a NoneType error. 请求艾德·阿维斯(Ed Avis)提出请求。


  • [mssql] [bug] Fixed issue where DDL generated for the MSSQL types DATETIME2, TIME and DATETIMEOFFSET with a precision of “zero” would not generate the precision field. 拉请求Jacobo de Vera礼貌。


杂项¶ T0>

  • [bug] [ext] Added support for the dict.pop() and dict.popitem() methods to the mutable.MutableDict class.


  • [bug] [py3k] Updates to internal getargspec() calls, some py36-related fixture updates, and alterations to two iterators to “return” instead of raising StopIteration, to allow tests to pass without errors or warnings on Py3.5, Py3.6, pull requests courtesy Jacob MacDonald, Luri de Silvio, and Phil Jones.


  • [bug] [ext] Fixed an issue in baked queries where the .get() method, used either directly or within lazy loads, didn’t consider the mapper’s “get clause” as part of the cache key, causing bound parameter mismatches if the clause got re-generated. 该子句由mappers快速缓存,但在高度并发的情况下,可能会在首次访问时多次生成。


  • [tests] [change] The ORM and Core tutorials, which have always been in doctest format, are now exercised within the normal unit test suite in both Python 2 and Python 3.

1.0.9 ¶ T0>


ORM ¶ T0>

  • [orm] [feature] 新增了新的方法Query.one_or_none();与Query.one()相同,但如果未找到任何行,则返回None。拉请求礼貌esiegerman。


  • [orm] [bug] [postgresql] Fixed regression in 1.0 where new feature of using “executemany” for UPDATE statements in the ORM (e.g. UPDATE statements are now batched with executemany() in a flush) would break on Postgresql and other RETURNING backends when using server-side version generation schemes, as the server side value is retrieved via RETURNING which is not supported with executemany.


  • [orm] [bug] Fixed rare TypeError which could occur when stringifying certain kinds of internal column loader options within internal logging.


  • [orm] [bug] Fixed bug in Session.bulk_save_objects() where a mapped column that had some kind of “fetch on update” value and was not locally present in the given object would cause an AttributeError within the operation.


  • [orm] [bug] Fixed 1.0 regression where the “noload” loader strategy would fail to function for a many-to-one relationship. 加载器使用API​​将“None”放入不再实际写入值的字典中;这是#3061的副作用


SQL ¶ T0>

  • [sql] [bug] Fixed regression in 1.0-released default-processor for multi-VALUES insert statement, #3288, where the column type for the default-holding column would not be propagated to the compiled statement in the case where the default was being used, leading to bind-level type handlers not being invoked.


的PostgreSQL ¶ T0>

  • [postgresql] [bug] An adjustment to the new Postgresql feature of reflecting storage options and USING of #3455 released in 1.0.6, to disable the feature for Postgresql versions < 8.2 where the reloptions column is not provided; this allows Amazon Redshift to again work as it is based on an 8.0.x version of Postgresql. 修正Pete Hollobon的礼貌。


预言¶ T0>

  • [oracle] [bug] [py3k] Fixed support for cx_Oracle version 5.2, which was tripping up SQLAlchemy’s version detection under Python 3 and inadvertently not using the correct unicode mode for Python 3. 这会导致绑定变量被错误地解释为NULL和行不会被返回的问题。



  • [oracle] [bug] Fixed bug in Oracle dialect where reflection of tables and other symbols with names quoted to force all-lower-case would not be identified properly in reflection queries. quoted_name结构现在应用于传入的符号名称,这些符号名称在“name normalize”过程中被强制为全部小写。


杂项¶ T0>

  • [feature] [ext] Added the AssociationProxy.info parameter to the AssociationProxy constructor, to suit the AssociationProxy.info accessor that was added in #2971. 这是可能的,因为AssociationProxy是显式构造的,不同于通过装饰器语法隐式构造的混合。


  • [bug] [examples] Fixed two issues in the “history_meta” example where history tracking could encounter empty history, and where a column keyed to an alternate attribute name would fail to track properly. 修正Alex Fraser的礼貌。

  • [bug] [sybase] Fixed two issues regarding Sybase reflection, allowing tables without primary keys to be reflected as well as ensured that a SQL statement involved in foreign key detection is pre-fetched up front to avoid driver issues upon nested queries. 在这里修改尤金Zapolsky;请注意,我们目前无法测试Sybase以在本地验证这些更改。


1.0.8 ¶ T0>


发动机¶ T0>

  • [engine] [bug] Fixed critical issue whereby the pool “checkout” event handler may be called against a stale connection without the “connect” event handler having been called, in the case where the pool attempted to reconnect after being invalidated and failed; the stale connection would remain present and would be used on a subsequent attempt. 这个问题在1.0.2之后的1.0系列中有更大的影响,因为它也向事件处理程序提供了一个空白的.info字典。在1.0.2之前,.info字典仍然是前一个。



源码¶ T0>

  • [sqlite] [bug] Fixed bug in SQLite dialect where reflection of UNIQUE constraints that included non-alphabetic characters in the names, like dots or spaces, would not be reflected with their name.

    This change is also backported to: 0.9.10


杂项¶ T0>

  • [misc] [bug] Fixed an issue where a particular base class within utils didn’t implement __slots__, and therefore meant all subclasses of that class didn’t either, negating the rationale for __slots__ to be in use. Didn’t cause any issue except on IronPython which apparently does not implement __slots__ behavior compatibly with cPython.


1.0.7 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed 1.0 regression where value objects that override __eq__() to return a non-boolean-capable object, such as some geoalchemy types as well as numpy types, were being tested for bool() during a unit of work update operation, where in 0.9 the return value of __eq__() was tested against “is True” to guard against this.


  • [orm] [bug] Fixed 1.0 regression where a “deferred” attribute would not populate correctly if it were loaded within the “optimized inheritance load”, which is a special SELECT emitted in the case of joined table inheritance used to populate expired or unloaded attributes against a joined table without loading the base table. 这与SQLA 1.0不再猜测加载延迟列的事实有关,必须明确指示。


  • [orm] [bug] Fixed 1.0 regression where the “parent entity” of a synonym- mapped attribute on top of an aliased() object would resolve to the original mapper, not the aliased() version of it, thereby causing problems for a Query that relies on this attribute (e.g. it’s the only representative attribute given in the constructor) to figure out the correct FROM clause for the query.


orm declarative

  • [bug] [orm] [declarative] Fixed bug in AbstractConcreteBase extension where a column setup on the ABC base which had a different attribute name vs. column name would not be correctly mapped on the final base class. 0.9上的失败将是无声的,而在1.0上它引发了ArgumentError,所以在1.0之前可能没有被注意到。


发动机¶ T0>

  • [engine] [bug] Fixed regression where new methods on ResultProxy used by the ORM Query object (part of the performance enhancements of #3175) would not raise the “this result does not return rows” exception in the case where the driver (typically MySQL) fails to generate cursor.description correctly; an AttributeError against NoneType would be raised instead.


  • [engine] [bug] Fixed regression where ResultProxy.keys() would return un-adjusted internal symbol names for “anonymous” labels, which are the “foo_1” types of labels we see generated for SQL functions without labels and similar. 这是性能增强的一个副作用,作为#918的一部分。


SQL ¶ T0>

  • [sql] [feature] Added a ColumnElement.cast() method which performs the same purpose as the standalone cast() function. 拉请求塞巴斯蒂安银行。

    References: #3459, pull request bitbucket:56

  • [sql] [bug] Fixed bug where coersion of literal True or False constant in conjunction with and_() or or_() would fail with an AttributeError.


  • [sql] [bug] Fixed potential issue where a custom subclass of FunctionElement or other column element that incorrectly states ‘None’ or any other invalid object as the .type attribute will report this exception instead of recursion overflow.


  • [sql] [bug] Fixed bug where the modulus SQL operator wouldn’t work in reverse due to a missing __rmod__ method. 请求礼物dan-gittik。


架构¶ T0>

  • [schema] [feature] 增加了Postgresql和Oracle支持的对CREATE SEQUENCE的MINVALUE,MAXVALUE,NO MINVALUE,NO MAXVALUE和CYCLE参数的支持。请求礼貌jakeogh。


1.0.6 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed a major regression in the 1.0 series where the version_id_counter feature would cause an object’s version counter to be incremented when there was no net change to the object’s row, but instead an object related to it via relationship (e.g. typically many-to-one) were associated or de-associated with it, resulting in an UPDATE statement that updates the object’s version counter and nothing else. 在使用相对较新的“服务器端”和/或“编程/条件”版本计数器特性的情况下(例如,将version_id_generator设置为False),该错误可能会导致UPDATE,而不会生成有效的SET子句。¶ T0>


  • [orm] [bug] Fixed 1.0 regression where the enhanced behavior of single-inheritance joins of #3222 takes place inappropriately for a JOIN along explicit join criteria with a single-inheritance subclass that does not make use of any discriminator, resulting in an additional “AND NULL” clause.


  • [orm] [bug] Fixed bug in new Session.bulk_update_mappings() feature where the primary key columns used in the WHERE clause to locate the row would also be included in the SET clause, setting their value to themselves unnecessarily. 拉请求Patrick Hayes。


  • [orm] [bug] Fixed an unexpected-use regression whereby custom Comparator objects that made use of the __clause_element__() method and returned an object that was an ORM-mapped InstrumentedAttribute and not explicitly a ColumnElement would fail to be correctly handled when passed as an expression to Session.query(). 0.9中的逻辑碰巧成功了,所以现在支持这个用例。


SQL ¶ T0>

  • [sql] [bug] Fixed a bug where clause adaption as applied to a Label object would fail to accommodate the labeled SQL expression in all cases, such that any SQL operation that made use of Label.self_group() would use the original unadapted expression. 其中一个影响是ORM aliased()结构不能完全容纳由column_property映射的属性,这样当属性为用于某些类型的SQL比较。


的PostgreSQL ¶ T0>

  • [postgresql] [feature] 使用新的关键字参数postgresql_with增加了对CREATE INDEX下存储参数的支持。还增加了对反射的支持,以支持postgresql_with标志以及postgresql_using标志,该标志现在将被设置在Index对象上,并在Inspector.get_indexes()的结果中出现在新的“dialect_options”字典中。拉请求Pete Hollobon提供。


  • [postgresql] [feature] Added new execution option max_row_buffer which is interpreted by the psycopg2 dialect when the stream_results option is used, which sets a limit on the size of the row buffer that may be allocated. 这个值也是基于发送到Query.yield_per()的整数值提供的。拉请求礼貌mcclurem。


  • [postgresql] [bug] [pypy] Re-fixed this issue first released in 1.0.5 to fix psycopg2cffi JSONB support once again, as they suddenly switched on unconditional decoding of JSONB types in version 2.7.1. 版本检测现在指定2.7.1作为我们应该期望DBAPI为我们执行json编码的地方。


  • [postgresql] [bug] Repaired the ExcludeConstraint construct to support common features that other objects like Index now do, that the column expression may be specified as an arbitrary SQL expression such as cast or text.



  • [mssql] [bug] Fixed issue when using VARBINARY type in conjunction with an INSERT of NULL + pyodbc; pyodbc requires a special object be passed in order to persist NULL. As the VARBINARY type is now usually the default for LargeBinary due to #3039, this issue is partially a regression in 1.0. pymssql驱动似乎不受影响。


杂项¶ T0>

  • [bug] [documentation] Fixed an internal “memoization” routine for method types such that a Python descriptor is no longer used; repairs inspectability of these methods including support for Sphinx documentation.


1.0.5 ¶ T0>


ORM ¶ T0>

  • [orm] [feature] Added new event InstanceEvents.refresh_flush(), invoked when an INSERT or UPDATE level default value fetched via RETURNING or Python-side default is invoked within the flush process. 这是为了提供一个钩子,它不再是#3167的结果,其中属性和验证事件在flush过程中不再被调用。


  • [orm] [bug] The “lightweight named tuple” used when a Query returns rows failed to implement __slots__ correctly such that it still had a __dict__. 这已经解决了,但是在极不可能的情况下,有人为返回的元组赋值,这将不再有效。


发动机¶ T0>

  • [engine] [feature] Added new engine event ConnectionEvents.engine_disposed(). Engine.dispose()方法被调用后调用。

  • [engine] [feature] Adjustments to the engine plugin hook, such that the URL.get_dialect() method will continue to return the ultimate Dialect object when a dialect plugin is used, without the need for the caller to be aware of the Dialect.get_dialect_cls() method.


  • [engine] [bug] Fixed bug where known boolean values used by engine_from_config() were not being parsed correctly; these included pool_threadlocal and the psycopg2 argument use_native_unicode.


  • [engine] [bug] Added support for the case of the misbehaving DBAPI that has pep-249 exception names linked to exception classes of an entirely different name, preventing SQLAlchemy’s own exception wrapping from wrapping the error appropriately. The SQLAlchemy dialect in use needs to implement a new accessor DefaultDialect.dbapi_exception_translation_map to support this feature; this is implemented now for the py-postgresql dialect.


  • [engine] [bug] Fixed bug involving the case when pool checkout event handlers are used and connection attempts are made in the handler itself which fail, the owning connection record would not be freed until the stack trace of the connect error itself were freed. 对于仅使用单个连接的测试池的情况,这意味着该池将被完全检出,直到该堆栈跟踪被释放。这主要影响非常具体的调试情况,并且不太可能在任何生产应用程序中显示出来。修复程序在重新引发捕获的异常之前应用显式签入记录。


SQL ¶ T0>

  • [sql] [feature] 增加了对Insert.from_select()中SELECT存在的CTE的官方支持。这个行为意外地工作到0.9.9,当它不再作为#3248的一部分而不相关的改变时。请注意,这是在SELECT之前的INSERT之后的WITH子句的呈现;在INSERT,UPDATE,DELETE顶层呈现的CTE的全部功能是针对以后版本的新功能。

    This change is also backported to: 0.9.10


的PostgreSQL ¶ T0>

  • [postgresql] [bug] [pypy] Repaired some typing and test issues related to the pypy psycopg2cffi dialect, in particular that the current 2.7.0 version does not have native support for the JSONB type. psycopg2功能的版本检测已被调整为psycopg2cffi的特定子版本。此外,psycopg2cffi下的全系列psycopg2功能已启用测试覆盖。



  • [mssql] [bug] 为MSSQL方言legacy_schema_aliasing添加了一个新的方言标志,当设置为False时,会禁用一个非常陈旧和过时的行为,将所有符合模式限制的表名称变为别名,以解决SQL Server无法在所有情况下解析多部分标识符名称的旧的且不再可定位的问题。该行为阻止了更复杂的语句正常工作,包括使用提示的语句以及嵌入相关SELECT语句的CRUD语句。而不是继续修复该功能来处理更复杂的语句,最好是禁用它,因为任何现代SQL服务器版本都不再需要它。对于1.0.x系列,该标志默认为True,这个版本系列的当前行为保持不变。在1.1系列中,它将默认为False。对于1.0系列,如果没有显式设置任何值,则会在语句中首次使用模式限定表时发出警告,这表明所有现代SQL Server版本都将该标志设置为False。


    Legacy Schema Mode


杂项¶ T0>

  • [feature] [ext] Added support for *args to be passed to the baked query initial callable, in the same way that *args are supported for the BakedQuery.add_criteria() and BakedQuery.with_criteria() methods. 最初的PR礼貌直到INADA。


  • [feature] [ext] MutableBase MutableBase._get_listen_keys()添加了一个新的半公开方法。Overriding this method is needed in the case where a MutableBase subclass needs events to propagate for attribute keys other than the key to which the mutable type is associated with, when intercepting the InstanceEvents.refresh() or InstanceEvents.refresh_flush() events. 当前的例子是使用MutableComposite的合成。


  • [bug] [ext] Fixed regression in the sqlalchemy.ext.mutable extension as a result of the bugfix for #3167, where attribute and validation events are no longer called within the flush process. 当列级别的Python端默认负责在INSERT或UPDATE上生成新值时,或者在RETURNING子句中为“eager defaults”模式提取值时,可变扩展依赖于此行为。新的价值不会受到任何事件的影响,而且可变的延伸不能建立适当的强制或历史聆听。添加了一个新的事件InstanceEvents.refresh_flush(),这个可变扩展现在可以用于这个用例。


1.0.4 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed unexpected-use regression where in the odd case that the primaryjoin of a relationship involved comparison to an unhashable type such as an HSTORE, lazy loads would fail due to a hash-oriented check on the statement parameters, modified in 1.0 as a result of #3061 to use hashing and modified in #3368 to occur in cases more common than “load on pending”. 现在检查__hash__属性的值。


  • [orm] [bug] Liberalized an assertion that was added as part of #3347 to protect against unknown conditions when splicing inner joins together within joined eager loads with innerjoin=True; if some of the joins use a “secondary” table, the assertion needs to unwrap further joins in order to pass.


  • [orm] [bug] Repaired / added to tests yet more expressions that were reported as failing with the new ‘entity’ key value added to Query.column_descriptions, the logic to discover the “from” clause is again reworked to accommodate columns from aliased classes, as well as to report the correct value for the “aliased” flag in these cases.


架构¶ T0>

杂项¶ T0>

  • [bug] [ext] Fixed bug where when using extended attribute instrumentation system, the correct exception would not be raised when class_mapper() were called with an invalid input that also happened to not be weak referencable, such as an integer.

    This change is also backported to: 0.9.10


  • [bug] [tests] [pypy] 修正了阻止“pypy setup.py test”正常工作的导入。

    This change is also backported to: 0.9.10


1.0.3 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] [pypy] Fixed regression from 0.9.10 prior to release due to #3349 where the check for query state on Query.update() or Query.delete() compared the empty tuple to itself using is, which fails on Pypy to produce True in this case; this would erronously emit a warning in 0.9 and raise an exception in 1.0.


  • [orm] [bug] Fixed regression from 0.9.10 prior to release where the new addition of entity to the Query.column_descriptions accessor would fail if the target entity was produced from a core selectable such as a Table or CTE object.


  • [orm] [bug] Fixed regression within the flush process when an attribute were set to a SQL expression for an UPDATE, and the SQL expression when compared to the previous value of the attribute would produce a SQL comparison other than == or !=, the exception “Boolean value of this clause is not defined” would raise. 该修复确保工作单元不会以这种方式解释SQL表达式。


  • [orm] [bug] Fixed unexpected use regression due to #2992 where textual elements placed into the Query.order_by() clause in conjunction with joined eager loading would be added to the columns clause of the inner query in such a way that they were assumed to be table-bound column names, in the case where the joined eager load needs to wrap the query in a subquery to accommodate for a limit/offset.

    最初,这里的行为是有意的,因为诸如query(User).order_by('name').limit(1)的查询将通过user.name即使查询是通过加入预先加载进入子查询来修改的,因为'name'会被解释为一个符号位于FROM子句中,在这种情况下User.name,然后将其复制到列子句中,以确保它存在于ORDER BY中。但是,该功能无法预测到order_by("name")引用了本地列子句中存在的特定标签名称,而不是绑定到FROM子句中可选的名称的情况。

    Beyond that, the feature also fails for deprecated cases such as order_by("name desc"), which, while it emits a warning that text() should be used here (note that the issue does not impact cases where text() is used explicitly), still produces a different query than previously where the “name desc” expression is copied into the columns clause inappropriately. 分辨率是这样的,当增加内部子句时,特征的“加入的加载”方面将跳过这些所谓的“标签引用”表达式,好像它们已经是text()


  • [orm] [bug] Fixed a regression regarding the MapperEvents.instrument_class() event where its invocation was moved to be after the class manager’s instrumentation of the class, which is the opposite of what the documentation for the event explicitly states. The rationale for the switch was due to Declarative taking the step of setting up the full “instrumentation manager” for a class before it was mapped for the purpose of the new @declared_attr features described in Improvements to declarative mixins, @declared_attr and related features, but the change was also made against the classical use of mapper() for consistency. 但是,SQLSoup依赖于在经典映射下的任何检测之前发生的检测事件。在古典和声明式映射的情况下,行为被恢复,后者通过使用简单的记忆而不使用类管理器来实现。


  • [orm] [bug] Fixed issue in new QueryEvents.before_compile() event where changes made to the Query object’s collection of entities to load within the event would render in the SQL, but would not be reflected during the loading process.


发动机¶ T0>

  • [engine] [feature] 添加了新功能,以支持具有高级功能的引擎/池插件。在检出的连接包装器的连接池以及_ConnectionRecord中添加了一个新的“软无效”特性。这与现代游泳池失效相似,因为连接不被主动关闭,而是仅在下次结账时被循环使用;这实质上是该功能的每个连接版本。添加新的事件PoolEvents.soft_invalidate以补充它。



  • [engine] [feature] Added new event DialectEvents.do_connect, which allows interception / replacement of when the Dialect.connect() hook is called to create a DBAPI connection. 还添加了允许外部插件使用入口点将事件添加到现有方言的方言插件钩子Dialect.get_dialect_cls()Dialect.engine_created() T6>


SQL ¶ T0>

  • [sql] [feature] Added a placeholder method TypeEngine.compare_against_backend() which is now consumed by Alembic migrations as of 0.7.6. 用户定义的类型可以实现这个方法来帮助比较一个类型和一个从数据库反射的类型。

  • [sql] [bug] Fixed bug where the truncation of long labels in SQL could produce a label that overlapped another label that is not truncated; this because the length threshhold for truncation was greater than the portion of the label that remains after truncation. 这两个价值现在已经是一样了, label_length - 6。这样做的效果是,较短的列标签将被“截断”,以前它们不会被截断。


  • [sql] [bug] Fixed regression due to #3282 where the tables collection passed as a keyword argument to the DDLEvents.before_create(), DDLEvents.after_create(), DDLEvents.before_drop(), and DDLEvents.after_drop() events would no longer be a list of tables, but instead a list of tuples which contained a second entry with foreign keys to be added or dropped. 由于tables集合虽然被证明不一定是稳定的,但已经被依赖,这种变化被认为是一种回归。此外,在某些情况下,“集合”将会是一个迭代器,如果过早迭代,会导致操作失败。该集合现在是所有情况下的表对象列表,并且现在添加了用于此集合格式的测试覆盖。


杂项¶ T0>

  • [bug] [ext] Fixed bug in association proxy where an any()/has() on an relationship->scalar non-object attribute comparison would fail, e.g. filter(Parent.some_collection_to_attribute.any(Child.attr == 'foo'))


1.0.2 ¶ T0>


orm declarative

  • [bug] [orm] [declarative] Fixed unexpected use regression regarding the declarative __declare_first__ and __declare_last__ accessors where these would no longer be called on the superclass of the declarative base.


SQL ¶ T0>

  • [sql] [bug] Fixed a regression that was incorrectly fixed in 1.0.0b4 (hence becoming two regressions); reports that SELECT statements would GROUP BY a label name and fail was misconstrued that certain backends such as SQL Server should not be emitting ORDER BY or GROUP BY on a simple label name at all; when in fact, we had forgotten that 0.9 was already emitting ORDER BY on a simple label name for all backends, as described in Label constructs can now render as their name alone in an ORDER BY, even though 1.0 includes a rewrite of this logic as part of #2992. 至于发射GROUP BY对一个简单的标签,即使Postgresql也会引发一个错误,即使要标记的标签应该是显而易见的,所以显然GROUP BY不应该以这种方式自动呈现。

    在1.0.2中,SQL Server,Firebird等将在传递也存在于columns子句中的Label结构时,在简单标签名称上再次发出ORDER BY。另外,只有当传递Label结构时,没有后端才会针对简单标签名称发出GROUP BY。


1.0.1 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed issue where a query of the form query(B).filter(B.a != A(id=7)) would render the NEVER_SET symbol, when given a transient object. 对于持久对象,它总是使用持久数据库值而不是当前设置的值。假设autoflush已打开,通常对于永久性值来说不会很明显,因为在任何情况下,任何挂起的更改都将被刷新。However, this is inconsistent vs. the logic used for the non-negated comparison, query(B).filter(B.a == A(id=7)), which does use the current value and additionally allows comparisons to transient objects. 现在比较使用当前值而不是数据库持久化值。

    Unlike the other NEVER_SET issues that are repaired as regressions caused by #3061 in this release, this particular issue is present at least as far back as 0.8 and possibly earlier, however it was discovered as a result of repairing the related NEVER_SET issues.


  • [orm] [bug] Fixed unexpected use regression cause by #3061 where the NEVER_SET symbol could leak into relationship-oriented queries, including filter() and with_parent() queries. 在所有情况下,都会返回None符号,但是在任何情况下,这些查询都不会被正确支持,并且会在不使用IS运算符的情况下将其与NULL进行比较。出于这个原因,警告也被添加到当前不提供IS NULL的关系查询的子集中。


  • [orm] [bug] Fixed a regression caused by #3061 where the NEVER_SET symbol could leak into a lazyload query, subsequent to the flush of a pending object. 这通常会发生多对一的关系,而不使用简单的“获取”策略。好消息是修复效率比0.9提高了,因为我们现在可以在检测到参数中的NEVER_SET符号时完全跳过SELECT语句;在#3061之前,我们无法辨别这里是否设置了None。


发动机¶ T0>

  • [engine] [bug] Added the string value "none" to those accepted by the Pool.reset_on_return parameter as a synonym for None, so that string values can be used for all settings, allowing utilities like engine_from_config() to be usable without issue.

    This change is also backported to: 0.9.10


SQL ¶ T0>

  • [sql] [bug] Fixed issue where a straight SELECT EXISTS query would fail to assign the proper result type of Boolean to the result mapping, and instead would leak column types from within the query into the result map. 这个问题也存在于0.9及更早的版本中,但在这些版本中影响较小。在1.0中,由于#918,这成为一个回归,因为我们现在依赖结果映射非常准确,否则我们可以将结果类型的处理器分配到错误的列。在所有版本中,这个问题也有一个简单的EXISTS不会应用布尔类型处理程序,导致后端简单的1/0值没有本地布尔值而不是真/假。修复包括一个EXISTS列参数将像其他列表达式那样被匿名标记;对于纯布尔表达式(比如not_(True()))实现了类似的修复。


源码¶ T0>

  • [sqlite] [bug] Fixed a regression due to #3282, where due to the fact that we attempt to assume the availability of ALTER when creating/dropping schemas, in the case of SQLite we simply said to not worry about foreign keys at all, since ALTER is not available, when creating and dropping tables. 这意味着在SQLite的情况下基本上跳过了表的排序,对于绝大多数SQLite用例来说,这不是问题。


    In order to maintain the new feature of #3282 while still allowing a SQLite DROP operation to maintain ordering, we now do the sort with full FKs taken under consideration, and if we encounter an unresolvable cycle, only then do we forego attempting to sort the tables; we instead emit a warning and go with the unsorted list. If an environment needs both ordered DROPs and has foreign key cycles, then the warning notes they will need to restore the use_alter flag to their ForeignKey and ForeignKeyConstraint objects so that just those objects will be omitted from the dependency sort.


    The use_alter flag on ForeignKeyConstraint is (usually) no longer needed - 包含有关SQLite的更新注释。


火鸟¶ T0>

  • [firebird] [bug] Fixed a regression due to #3034 where limit/offset clauses were not properly interpreted by the Firebird dialect. 请求礼貌有效的git。


  • [firebird] [bug] Fixed support for “literal_binds” mode when using limit/offset with Firebird, so that the values are again rendered inline when this is selected. #3034相关


1.0.0 ¶ T0>


ORM ¶ T0>

  • [orm] [feature] Added new argument Query.update.update_args which allows kw arguments such as mysql_limit to be passed to the underlying Update construct. 请求Amir Sadoughi提供。


  • [orm] [bug] 多次处理Query.join()到同一个目标时发现不一致。它隐式地只在关系连接的情况下进行去除,并且由于#3233,在1.0中,连接到同一个表的两次表现不同于0.9,因为它不再是错误的别名。为了帮助记录这个变化,在迁移说明中关于#3233的措词已经被推广,并且当对Query.join()被调用时已经添加警告目标关系不止一次。


  • [orm] [bug] Made a small improvement to the heuristics of relationship when determining remote side with semi-self-referential (e.g. two joined inh subclasses referring to each other), non-simple join conditions such that the parententity is taken into account and can reduce the need for using the remote() annotation; this can restore some cases that might have worked without the annotation prior to 0.9.4 via #2948.


SQL ¶ T0>

  • [sql] [feature] The topological sorting used to sort Table objects and available via the MetaData.sorted_tables collection will now produce a deterministic ordering; that is, the same ordering each time given a set of tables with particular names and dependencies. 这是为了帮助比较DDL脚本和其他用例。表被发送到按名称排序的拓扑排序,拓扑排序本身将以有序方式处理输入数据。拉请求塞巴斯蒂安银行礼貌。


  • [sql] [bug] Fixed issue where a MetaData object that used a naming convention would not properly work with pickle. 如果使用不带钩的MetaData对象来构建附加表格,则该属性被跳过导致不一致和失败。

    This change is also backported to: 0.9.10


的PostgreSQL ¶ T0>

  • [postgresql] [bug] Fixed a long-standing bug where the Enum type as used with the psycopg2 dialect in conjunction with non-ascii values and native_enum=False would fail to decode return results properly. 这源于PG postgresql.ENUM类型曾经是一个没有“非本地”选项的独立类型。

    This change is also backported to: 0.9.10



  • [mssql] [bug] Fixed a regression where the “last inserted id” mechanics would fail to store the correct value for MSSQL on an INSERT where the primary key value was present in the insert params before execution, as well as in the case where an INSERT from SELECT would state the target columns as column objects, instead of string keys.


  • [mssql] [bug] 使用现在在pymssql中的Binary构造函数,而不是打补丁。请求拉米罗·莫拉莱斯提供。


杂项¶ T0>

  • [bug] [tests] 修正测试运行时使用的路径;对于sqla_nose.py和py.test,“./lib”前缀再次插入到sys.path的头部,但只有在没有设置sys.flags.no_user_site的情况下。这使得它的行为就像Python在默认情况下在当前路径中放置“。”一样。对于tox,我们正在设置PYTHONNOUSERSITE标志。


1.0.0b5 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed bug where the state tracking within multiple, nested Session.begin_nested() operations would fail to propagate the “dirty” flag for an object that had been updated within the inner savepoint, such that if the enclosing savepoint were rolled back, the object would not be part of the state that was expired and therefore reverted to its database state.

    This change is also backported to: 0.9.10


  • [orm] [bug] Query doesn’t support joins, subselects, or special FROM clauses when using the Query.update() or Query.delete() methods; instead of silently ignoring these fields if methods like Query.join() or Query.select_from() has been called, an error is raised. 在0.9.10中只会发出警告。


  • [orm] [bug] Added a list() call around a weak dictionary used within the commit phase of the session, which without it could cause a “dictionary changed size during iter” error if garbage collection interacted within the process. 变更是由#3139引入的。

  • [orm] [bug] Fixed a bug related to “nested” inner join eager loading, which exists in 0.9 as well but is more of a regression in 1.0 due to #3008 which turns on “nested” by default, such that a joined eager load that travels across sibling paths from a common ancestor using innerjoin=True will correctly splice each “innerjoin” sibling into the appropriate part of the join, when a series of inner/outer joins are mixed together.


SQL ¶ T0>

  • [sql] [bug] The warning emitted by the unicode type for a non-unicode type has been liberalized to warn for values that aren’t even string values, such as integers; previously, the updated warning system of 1.0 made use of string formatting operations which would raise an internal TypeError. 尽管理想情况下这些情况应该完全提升,但是一些像SQLite和MySQL这样的后端可以接受它们,并且有可能被遗留代码使用,更不用说如果关闭目标后端的unicode转换,它们将会一直通过。 T0>


的PostgreSQL ¶ T0>

  • [postgresql] [bug] Fixed bug where updated PG index reflection as a result of #3184 would cause index operations to fail on Postgresql versions 8.4 and earlier. 使用较早版本的Postgresql时,现在禁用了这些增强功能。


1.0.0b4 ¶ T0>


SQL ¶ T0>

  • [sql] [bug] Fixed bug in new “label resolution” feature of #2992 where a label that was anonymous, then labeled again with a name, would fail to be locatable via a textual label. 当一个映射的column_property()在查询中被赋予一个明确的标签时,这种情况自然会发生。


  • [sql] [bug] Fixed bug in new “label resolution” feature of #2992 where the string label placed in the order_by() or group_by() of a statement would place higher priority on the name as found inside the FROM clause instead of a more locally available name inside the columns clause.


架构¶ T0>

MySQL的¶ T0>

  • [mysql] [bug] [pymysql] Fixed unicode support for PyMySQL when using an “executemany” operation with unicode parameters. SQLAlchemy现在将语句以及绑定参数作为unicode对象传递,因为PyMySQL通常在内部使用字符串插值来生成最终语句,而在executemany的情况下,仅在最后语句中执行“编码”步骤。¶ T0>

    This change is also backported to: 0.9.10



  • [mssql] [bug] [sybase] [firebird] [oracle] Turned off the “simple order by” flag on the MSSQL, Oracle dialects; this is the flag that per #2992 causes an order by or group by an expression that’s also in the columns clause to be copied by label, even if referenced as the expression object. MSSQL的行为现在是默认情况下复制整个表达式的旧行为,因为MSSQL可以挑选这些行为,特别是在GROUP BY表达式中。Firebird和Sybase方言的标志也被关闭了。




1.0.0b3 ¶ T0>


MySQL的¶ T0>

  • [mysql] [bug] 修复了被无意中注释掉的问题#2771的提交。


1.0.0b2 ¶ T0>


ORM ¶ T0>

  • [orm] [bug] Fixed unexpected use regression from pullreq github:137 where Py2K unicode literals (e.g. u"") would not be accepted by the relationship.cascade option. 请求礼貌Julien Castets。


orm declarative

  • [orm] [declarative] [change] 松散了一些添加到@declared_attr对象的限制,以防止在声明过程之外调用它们;这与#3150的增强有关,允许@declared_attr返回一个基于当前类缓存的值。异常提升已经被删除,并且行为发生了改变,所以在声明过程之外,由@declared_attr装饰的函数每次被调用,就像普通的@property没有使用任何缓存,因为在这个阶段没有任何缓存。


发动机¶ T0>

  • [engine] [bug] The “auto close” for ResultProxy is now a “soft” close. 也就是说,在使用提取方法排除所有行之后,DBAPI游标被释放,并且可以安全地丢弃该对象,但可以继续调用获取方法,以便返回结果对象(无为fetchone,为fetchmany和fetchall空列表)。Only if ResultProxy.close() is called explicitly will these methods raise the “result is closed” error.


MySQL的¶ T0>

  • [mysql] [bug] [py3k] Fixed the mysql.BIT type on Py3K which was not using the ord() function correctly. 请求提供David Marin。

    This change is also backported to: 0.9.10

    References: #3333, pull request github:158

  • [mysql] [bug] Fixes to fully support using the 'utf8mb4' MySQL-specific charset with MySQL dialects, in particular MySQL-Python and PyMySQL. 另外,报告“koi8u”或“eucjpms”等更多不寻常字符的MySQL数据库也能正常工作。请求托马斯·格兰杰提供。

    References: #2771, pull request bitbucket:49

1.0.0b1 ¶ T0>


版本1.0.0b1是1.0系列的第一个版本。这里描述的许多变化也出现在0.9和0.8系列中。对于特定于1.0的更改,强调兼容性问题,请参阅What’s New in SQLAlchemy 1.0?

一般¶ T0>

  • [general] [feature] 通过对许多内部对象使用__slots__,结构内存使用得到了改进。这种优化尤其适用于具有大量表和列的大型应用程序的基本内存大小,并且大大减少了各种大容量对象(包括事件监听内部事件,比较对象和ORM属性和加载器策略的一部分)的内存大小系统。

  • [general] [bug] The __module__ attribute is now set for all those SQL and ORM functions that are derived as “public factory” symbols, which should assist with documentation tools being able to report on the target module.


ORM ¶ T0>

  • [orm] [feature] 向由Query.column_descriptions返回的字典添加了一个新的条目"entity"这是指由表达式引用的主要ORM映射类或别名类。"type"的现有条目相比,即使从列表达式提取,它也将始终是映射实体,如果给定表达式是纯粹核心表达式,则它将始终为None。另见#3403,它修复了0.9.10版本中未发布但在1.0版本中发布的回归。

    This change is also backported to: 0.9.10


  • [orm] [feature] 增加了一个新的参数Session.connection.execution_options,它可以用来在Connection上设置执行选项在交易开始之前先检查出来。这用于在事务启动之前设置连接上的隔离级别等选项。


    Setting Transaction Isolation Levels - 新的文档部分详细介绍了使用会话设置事务隔离的最佳实践。



  • [orm] [feature] Added new method Session.invalidate(), functions similarly to Session.close(), except also calls Connection.invalidate() on all connections, guaranteeing that they will not be returned to the connection pool. 这在例如情况下是有用的在进一步使用连接不安全的情况下处理gevent超时,即使是回滚。


  • [orm] [feature] The “primaryjoin” model has been stretched a bit further to allow a join condition that is strictly from a single column to itself, translated through some kind of SQL function or expression. 这是一种实验,但概念的第一个证明是“物化路径”连接条件,其中路径字符串与“like”相比较。The ColumnOperators.like() operator has also been added to the list of valid operators to use in a primaryjoin condition.



  • [orm] [feature] Added new utility function make_transient_to_detached() which can be used to manufacture objects that behave as though they were loaded from a session, then detached. 不存在的属性被标记为过期的,并且该对象可以被添加到Session中,在那里它将像一个永久的一样。



  • [orm] [feature] 添加了一个新的事件套件QueryEventsThe QueryEvents.before_compile() event allows the creation of functions which may place additional modifications to Query objects before the construction of the SELECT statement. It is hoped that this event be made much more useful via the advent of a new inspection system that will allow for detailed modifications to be made against Query objects in an automated fashion.




  • [orm] [feature] 在使用联接的加载加载时发生的子查询包装与一个一对多查询一起使用,该查询还具有LIMIT,OFFSET或DISTINCT在一个一对一关系,即relationship.uselist设置为False的一对多关系。这将在这些情况下产生更高效的查询。


  • [orm] [feature] 映​​射状态内部已经被重新设计,以允许特定于对象“过期”的callcounts减少50%,就像Session.commit()Session.expire_all(),以及在对象状态被垃圾收集时发生的“清除”步骤。


  • [orm] [feature] 当相同的多态标识被分配给同一层次结构中的两个不同的映射器时,会发出警告。这通常是一个用户错误,意味着两个不同的映射类型在加载时无法正确区分。拉请求塞巴斯蒂安银行。


  • [orm] [feature] 已经创建了一系列新的Session方法,这些方法直接将钩子挂接到工作单元的工作单元中,用于发出INSERT和UPDATE语句。如果使用正确,这个面向专家的系统可以允许使用ORM映射来生成批量插入和更新语句,批量插入到executemany组中,从而使得语句的执行速度可以与直接使用Core的速度相媲美。


    Bulk Operations


  • [orm] [feature] Added a parameter Query.join.isouter which is synonymous with calling Query.outerjoin(); this flag is to provide a more consistent interface compared to Core FromClause.join(). 请求Jonathan Vanasco提供。


  • [orm] [feature] Added new event handlers AttributeEvents.init_collection() and AttributeEvents.dispose_collection(), which track when a collection is first associated with an instance and when it is replaced. 这些处理程序取代collection.linker()注释。旧的钩子仍然通过一个事件适配器来支持。

  • [orm] [feature] The Query will raise an exception when Query.yield_per() is used with mappings or options where either subquery eager loading, or joined eager loading with collections, would take place. 这些加载策略目前与yield_per不兼容,所以通过提高这个错误,该方法更安全。可以使用lazyload('*')选项或Query.enable_eagerloads()来禁用预加载。

  • [orm] [feature] A new implementation for KeyedTuple used by the Query object offers dramatic speed improvements when fetching large numbers of column-oriented rows.


  • [orm] [feature] The behavior of joinedload.innerjoin as well as relationship.innerjoin is now to use “nested” inner joins, that is, right-nested, as the default behavior when an inner join joined eager load is chained to an outer join eager load.


  • [orm] [feature] UPDATE statements can now be batched within an ORM flush into more performant executemany() call, similarly to how INSERT statements can be batched; this will be invoked within flush to the degree that subsequent UPDATE statements for the same mapping and table involve the identical columns within the VALUES clause, that no SET-level SQL expressions are embedded, and that the versioning requirements for the mapping are compatible with the backend dialect’s ability to return a correct rowcount for an executemany operation.

  • [orm] [feature] The info parameter has been added to the constructor for SynonymProperty and ComparableProperty.


  • [orm] [feature] The InspectionAttr.info collection is now moved down to InspectionAttr, where in addition to being available on all MapperProperty objects, it is also now available on hybrid properties, association proxies, when accessed via Mapper.all_orm_descriptors.


  • [orm] [changed] The proc() callable passed to the create_row_processor() method of custom Bundle classes now accepts only a single “row” argument.

  • [orm] [changed] Deprecated event hooks removed: populate_instance, create_instance, translate_row, append_result

  • [orm] [bug] Fixed bugs in ORM object comparisons where comparison of many-to-one != None would fail if the source were an aliased class, or if the query needed to apply special aliasing to the expression due to aliased joins or polymorphic querying; also fixed bug in the case where comparing a many-to-one to an object state would fail if the query needed to apply special aliasing due to aliased joins or polymorphic querying.



  • [orm] [bug] Fixed bug where internal assertion would fail in the case where an after_rollback() handler for a Session incorrectly adds state to that Session within the handler, and the task to warn and remove this state (established by #2389) attempts to proceed.



  • [orm] [bug] Fixed bug where TypeError raised when Query.join() called with unknown kw arguments would raise its own TypeError due to broken formatting. 请求Malthe Borch提出请求。



  • [orm] [bug] Fixed bug in lazy loading SQL construction whereby a complex primaryjoin that referred to the same “local” column multiple times in the “column that points to itself” style of self-referential join would not be substituted in all cases. 这里确定替代的逻辑已被重新设计为更加开放。



  • [orm] [bug] The “wildcard” loader options, in particular the one set up by the orm.load_only() option to cover all attributes not explicitly mentioned, now takes into account the superclasses of a given entity, if that entity is mapped with inheritance mapping, so that attribute names within the superclasses are also omitted from the load. 此外,多态鉴别器列无条件地包含在列表中,就像主键列一样,所以即使设置了load_only(),子类型的多态加载也能正常工作。 t0 >



  • [orm] [bug] [pypy] Fixed bug where if an exception were thrown at the start of a Query before it fetched results, particularly when row processors can’t be formed, the cursor would stay open with results pending and not actually be closed. 对于像Pypy这样的解释器来说,这通常只是一个问题,在这种解释器中,游标并没有立即被GC化,而且在某些情况下会导致事务/锁的打开时间比所需的时间长。



  • [orm] [bug] Fixed a leak which would occur in the unsupported and highly non-recommended use case of replacing a relationship on a fixed mapped class many times, referring to an arbitrarily growing number of target mappers. 旧的关系被替换时会发出警告,但是如果映射已经用于查询,旧的关系仍然会在某些注册表中引用。



  • [orm] [bug] [sqlite] Fixed bug regarding expression mutations which could express itself as a “Could not locate column” error when using Query to select from multiple, anonymous column entities when querying against SQLite, as a side effect of the “join rewriting” feature used by the SQLite dialect.



  • [orm] [bug] Fixed bug where the ON clause for Query.join(), and Query.outerjoin() to a single-inheritance subclass using of_type() would not render the “single table criteria” in the ON clause if the from_joinpoint=True flag were set.



  • [orm] [bug] [engine] Fixed bug that affected generally the same classes of event as that of #3199, when the named=True parameter would be used. 一些事件将无法注册,而另一些则不能正确地调用事件参数,一般是在事件被“包装”以便以其他方式进行适应的情况下。“命名”机制已经重新排列,不会干扰内部包装函数所期望的参数签名。



  • [orm] [bug] Fixed bug that affected many classes of event, particularly ORM events but also engine events, where the usual logic of “de duplicating” a redundant call to event.listen() with the same arguments would fail, for those events where the listener function is wrapped. 一个断言将在registry.py中发生。现在这个说法已经被纳入重复数据删除检查中,并且还有一个简单的检查重复数据删除方法的好处。



  • [orm] [bug] Fixed warning that would emit when a complex self-referential primaryjoin contained functions, while at the same time remote_side was specified; the warning would suggest setting “remote side”. 现在只有在remote_side不存在时才会发出。



  • [orm] [bug] [eagerloading] Fixed a regression caused by #2976 released in 0.9.4 where the “outer join” propagation along a chain of joined eager loads would incorrectly convert an “inner join” along a sibling join path into an outer join as well, when only descendant paths should be receiving the “outer join” propagation; additionally, fixed related issue where “nested” join propagation would take place inappropriately between two sibling join paths.

    This change is also backported to: 0.9.7


  • [orm] [bug] Fixed a regression from 0.9.0 due to #2736 where the Query.select_from() method no longer set up the “from entity” of the Query object correctly, so that subsequent Query.filter_by() or Query.join() calls would fail to check the appropriate “from” entity when searching for attributes by string name.

    This change is also backported to: 0.9.7


  • [orm] [bug] Fixed bug where items that were persisted, deleted, or had a primary key change within a savepoint block would not participate in being restored to their former state (not in session, in session, previous PK) after the outer transaction were rolled back.

    This change is also backported to: 0.9.7


  • [orm] [bug] Fixed bug in subquery eager loading in conjunction with with_polymorphic(), the targeting of entities and columns in the subquery load has been made more accurate with respect to this type of entity and others.

    This change is also backported to: 0.9.7


  • [orm] [bug] Additional checks have been added for the case where an inheriting mapper is implicitly combining one of its column-based attributes with that of the parent, where those columns normally don’t necessarily share the same value. 这是通过#1892添加的现有支票的扩展。然而,这个新的检查只发出一个警告,而不是一个例外,以允许可能依赖现有行为的应用程序。



  • [orm] [bug] Modified the behavior of orm.load_only() such that primary key columns are always added to the list of columns to be “undeferred”; otherwise, the ORM can’t load the row’s identity. 显然,可以推迟映射的主键,并且ORM将会失败,这是没有改变的。But as load_only is essentially saying “defer all but X”, it’s more critical that PK cols not be part of this deferral.



  • [orm] [bug] Fixed a few edge cases which arise in the so-called “row switch” scenario, where an INSERT/DELETE can be turned into an UPDATE. 在这种情况下,多对一关系设置为无,或者在某些情况下标量属性设置为无可能不会被检测为净更改值,因此UPDATE不会重置上一行。这是由于一些尚未解决的方式属性历史的工作方式隐含地假设None不是真正的“改变”以前未设置的属性。另见#3061


    This change has been REVERTED in 0.9.6. 完整的修补程序将在SQLAlchemy 1.0版中。



  • [orm] [bug] Related to #3060, an adjustment has been made to the unit of work such that loading for related many-to-one objects is slightly more aggressive, in the case of a graph of self-referential objects that are to be deleted; the load of related objects is to help determine the correct order for deletion if passive_deletes is not set.


  • [orm] [bug] Fixed bug in SQLite join rewriting where anonymized column names due to repeats would not correctly be rewritten in subqueries. 这会影响任何一种子查询+连接的SELECT查询。



  • [orm] [bug] [sql] Fixes to the newly enhanced boolean coercion in #2804 where the new rules for “where” and “having” woudn’t take effect for the “whereclause” and “having” kw arguments of the select() construct, which is also what Query uses so wasn’t working in the ORM either.



  • [orm] [bug] Fixed bug in subquery eager loading where a long chain of eager loads across a polymorphic-subclass boundary in conjunction with polymorphic loading would fail to locate the subclass-link in the chain, erroring out with a missing property name on an AliasedClass.

    This change is also backported to: 0.9.5, 0.8.7


  • [orm] [bug] Fixed ORM bug where the class_mapper() function would mask AttributeErrors or KeyErrors that should raise during mapper configuration due to user errors. 属性/键错误的捕获已被更具体化,不包括配置步骤。

    This change is also backported to: 0.9.5, 0.8.7


  • [orm] [bug] Fixed bug where the session attachment error “object is already attached to session X” would fail to prevent the object from also being attached to the new session, in the case that execution continued after the error raise occurred.


  • [orm] [bug] The primary Mapper of a Query is now passed to the Session.get_bind() method when calling upon Query.count(), Query.update(), Query.delete(), as well as queries against mapped columns, column_property objects, and SQL functions and expressions derived from mapped columns. 这允许依赖于定制的Session.get_bind()方案或“绑定”元数据的会话在所有相关情况下工作。

    References: #3242, #3227, #1326

  • [orm] [bug] The PropComparator.of_type() modifier has been improved in conjunction with loader directives such as joinedload() and contains_eager() such that if two PropComparator.of_type() modifiers of the same base type/path are encountered, they will be joined together into a single “polymorphic” entity, rather than replacing the entity of type A with the one of type B. E.g. a joinedload of A.b.of_type(BSub1)->BSub1.c combined with joinedload of A.b.of_type(BSub2)->BSub2.c will create a single joinedload of A.b.of_type((BSub1, BSub2)) -> BSub1.c, BSub2.c, without the need for the with_polymorphic to be explicit in the query.


    Eager Loading of Specific or Polymorphic Subtypes - 包含说明新格式的更新示例。


  • [orm] [bug] Repaired support of the copy.deepcopy() call when used by the orm.util.CascadeOptions argument, which occurs if copy.deepcopy() is being used with relationship() (not an officially supported use case). 请求礼貌礼节。


  • [orm] [bug] Fixed bug where Session.expunge() would not fully detach the given object if the object had been subject to a delete operation that was flushed, but not committed. 这也会影响像make_transient()这样的相关操作。


  • [orm] [bug] A warning is emitted in the case of multiple relationships that ultimately will populate a foreign key column in conflict with another, where the relationships are attempting to copy values from different source columns. 这发生在具有重叠列的组合外键映射到每个指向不同引用列的关系的情况下。一个新的文档部分说明了这个例子,以及如何通过在每个关系的基础上具体指定“外部”列来解决这个问题。


  • [orm] [bug] The Query.update() method will now convert string key names in the given dictionary of values into mapped attribute names against the mapped class being updated. 以前,字符串名称被直接带入并传递给核心更新语句,而没有任何方法可以根据映射的实体进行解析。支持同义词和混合属性作为Query.update()的主题属性。


  • [orm] [bug] Improvements to the mechanism used by Session to locate “binds” (e.g. engines to use), such engines can be associated with mixin classes, concrete subclasses, as well as a wider variety of table metadata such as joined inheritance tables.


  • [orm] [bug] Fixed bug in single table inheritance where a chain of joins that included the same single inh entity more than once (normally this should raise an error) could, in some cases depending on what was being joined “from”, implicitly alias the second case of the single inh entity, producing a query that “worked”. 但是由于这种隐式别名并不是单表继承的意图,所以它并没有真正“起作用”,而且非常具有误导性,因为它并不总是显示出来。


  • [orm] [bug] The ON clause rendered when using Query.join(), Query.outerjoin(), or the standalone orm.join() / orm.outerjoin() functions to a single-inheritance subclass will now include the “single table criteria” in the ON clause even if the ON clause is otherwise hand-rolled; it is now added to the criteria using AND, the same way as if joining to a single-table target using relationship or similar.



  • [orm] [bug] A major rework to the behavior of expression labels, most specifically when used with ColumnProperty constructs with custom SQL expressions and in conjunction with the “order by labels” logic first introduced in 0.9. 修复包括:即使实体受到别名的影响,order_by(Entity.some_col_prop)现在也可以使用“按标号排序”规则,无论是通过继承呈现还是通过使用aliased()结构; (例如查询(Entity.some_prop, tt>> entity_alias.some_prop))多次渲染相同的列属性将标记每个出现的实体具有不同的标签,并且另外“按标签排序”规则将适用于两者(例如order_by(Entity.some_prop, entity_alias.some_prop) t7 >)。其他问题可能会阻止“按标签排序”逻辑在0.9下工作,最值得注意的是标签的状态可能发生变化,使得“根据标签排序”将停止工作,这取决于事情的调用方式。


  • [orm] [bug] Changed the approach by which the “single inheritance criterion” is applied, when using Query.from_self(), or its common user Query.count(). 现在,在内部子查询中而不是在外部子查询中指定了将行限制为特定类型的条件,因此即使“类型”列在列子句中不可用,也可以在“内部“查询。


  • [orm] [bug] Made a small adjustment to the mechanics of lazy loading, such that it has less chance of interfering with a joinload() in the very rare circumstance that an object points to itself; in this scenario, the object refers to itself while loading its attributes which can cause a mixup between loaders. “对象指向自己”的用例并不完全支持,但修复也会消除一些开销,所以现在是测试的一部分。


  • [orm] [bug] “resurrect”ORM事件已被删除。这个事件钩子没有用处,因为旧的“可变属性”系统在0.8被移除。


  • [orm] [bug] Fixed bug where attribute “set” events or columns with @validates would have events triggered within the flush process, when those columns were the targets of a “fetch and populate” operation, such as an autoincremented primary key, a Python side default, or a server-side default “eagerly” fetched via RETURNING.


  • [orm] [bug] [py3k] The IdentityMap exposed from Session.identity_map now returns lists for items() and values() in Py3K. 早期移植到Py3K这里有这些返回迭代器,当他们在技术上应该是“可迭代视图”..现在,列表是正常的。

  • [orm] [bug] The “evaluator” for query.update()/delete() won’t work with multi-table updates, and needs to be set to synchronize_session=False or synchronize_session=’fetch’; this now raises an exception, with a message to change the synchronize setting. 这是从0.9.7发出的警告升级而来的。


  • [orm] [change] Mapped attributes marked as deferred without explicit undeferral will now remain “deferred” even if their column is otherwise present in the result set in some way. 这是一个性能增强,因为当获得结果集时,ORM加载不再花费时间搜索每个延迟列。但是,对于依赖于此的应用程序,现在应该使用明确的undefer()或类似的选项。

  • [orm] [enhancement] Adjustment to attribute mechanics concerning when a value is implicitly initialized to None via first access; this action, which has always resulted in a population of the attribute, no longer does so; the None value is returned but the underlying attribute receives no set event. 这与集合如何工作是一致的,并允许属性机制的行为更加一致;特别是,如果值实际设置为None,则获取不带值的属性不会压缩应该继续的事件。

    其中绑定参数基于编译时选项以内联方式呈现为字符串。这个功能的工作是由Dobes Vandermeer提供的。


orm declarative

发动机¶ T0>

  • [engine] [feature] Added new user-space accessors for viewing transaction isolation levels; Connection.get_isolation_level(), Connection.default_isolation_level.


  • [engine] [feature] Added new event ConnectionEvents.handle_error(), a more fully featured and comprehensive replacement for ConnectionEvents.dbapi_error().

    This change is also backported to: 0.9.7


  • [engine] [feature] 可以发出一种新的警告,它可以“过滤”出现N次参数化字符串。这允许可以引用参数的参数化警告被传递固定次数,直到允许Python警告过滤器压制它们,并防止内存在Python的警告注册表中不受限制地增长。


  • [engine] [bug] Fixed bug in Connection and pool where the Connection.invalidate() method, or an invalidation due to a database disconnect, would fail if the isolation_level parameter had been used with Connection.execution_options(); the “finalizer” that resets the isolation level would be called on the no longer opened connection.



  • [engine] [bug] A warning is emitted if the isolation_level parameter is used with Connection.execution_options() when a Transaction is in play; DBAPIs and/or SQLAlchemy dialects such as psycopg2, MySQLdb may implicitly rollback or commit the transaction, or not change the setting til next transaction, so this is never safe.



  • [engine] [bug] The execution options passed to an Engine either via create_engine.execution_options or Engine.update_execution_options() are not passed to the special Connection used to initialize the dialect within the “first connect” event; dialects will usually perform their own queries in this phase, and none of the current available options should be applied here. 特别是,“autocommit”选项会导致尝试在这个初始连接中自动提交,由于Connection的非标准状态,会导致AttributeError失败。



  • [engine] [bug] 用于确定受INSERT或UPDATE影响的列的字符串键现在在对“编译缓存”缓存键作出贡献时被排序。这些键以前不是确定性排序的,这意味着相同的语句可以在相同的键上多次缓存,从内存和性能两个方面来说都是这样。



  • [engine] [bug] Fixed bug which would occur if a DBAPI exception occurs when the engine first connects and does its initial checks, and the exception is not a disconnect exception, yet the cursor raises an error when we try to close it. 在这种情况下,当我们尝试通过连接池记录游标关闭异常并且失败时,真正的异常将被废除,因为我们试图以在这种特定情况下不合适的方式访问池的记录器。 T0>



  • [engine] [bug] Fixed some “double invalidate” situations were detected where a connection invalidation could occur within an already critical section like a connection.close(); ultimately, these conditions are caused by the change in #2907, in that the “reset on return” feature calls out to the Connection/Transaction in order to handle it, where “disconnect detection” might be caught. However, it’s possible that the more recent change in #2985 made it more likely for this to be seen as the “connection invalidate” operation is much quicker, as the issue is more reproducible on 0.9.4 than 0.9.3.




  • [engine] [bug] The engine-level error handling and wrapping routines will now take effect in all engine connection use cases, including when user-custom connect routines are used via the create_engine.creator parameter, as well as when the Connection encounters a connection error on revalidation.


  • [engine] [bug] Removing (or adding) an event listener at the same time that the event is being run itself, either from inside the listener or from a concurrent thread, now raises a RuntimeError, as the collection used is now an instance of colletions.deque() and does not support changes while being iterated. 以前,使用普通的Python列表从事件本身中删除会导致静默失败。


SQL ¶ T0>

  • [sql] [feature] Liberalized the contract for Index a bit in that you can specify a text() expression as the target; the index no longer needs to have a table-bound column present if the index is to be manually added to the table, either via inline declaration or via Table.append_constraint().



  • 当设置为True呈现“BETWEEN SYMMETRIC”时,添加了新的标记expression.between.symmetric中的[sql] [feature] 还添加了一个新的否定运算符“notbetween_op”,该运算符现在允许像〜col.between(x, y) col NOT BETWEEN x AND y“,而不是一个括号中的NOT字符串。



  • [sql] [feature] The SQL compiler now generates the mapping of expected columns such that they are matched to the received result set positionally, rather than by name. 最初,这被看作是一种处理那些我们有难以预测的名字返回列的案例,尽管在现代使用这个问题已经被匿名标签克服了。在这个版本中,该方法基本上减少了几十个调用的每个结果的函数调用计数,或者对于更大的结果列集减少了更多的函数调用计数。The approach still degrades into a modern version of the old approach if any discrepancy in size exists between the compiled set of columns versus what was received, so there’s no issue for partially or fully textual compilation scenarios where these lists might not line up.


  • [sql] [feature] Literal values within a DefaultClause, which is invoked when using the Column.server_default parameter, will now be rendered using the “inline” compiler, so that they are rendered as-is, rather than as bound parameters.


  • [sql] [feature] The type of expression is reported when an object passed to a SQL expression unit can’t be interpreted as a SQL fragment; pull request courtesy Ryan P. Kelly.


  • [sql] [feature] Added a new parameter Table.tometadata.name to the Table.tometadata() method. Table.tometadata.schema类似,这个参数使得新复制的Table采用新名称而不是现有名称。这个增加了一个有趣的功能,就是用一个新的名字将一个Table对象复制到相同的 MetaData目标。拉提出请求n.d.帕克。¶ T0>


  • [sql] [feature] Exception messages have been spiffed up a bit. 如果为None,则不显示SQL语句和参数,从而减少与语句无关的错误消息的混淆。显示DBAPI级别异常的完整模块和类名,清楚地表明这是一个包装的DBAPI异常。语句和参数本身被限制在括号内,以便更好地将它们与错误消息和相互隔离。


  • [sql] [feature] Insert.from_select() now includes Python and SQL-expression defaults if otherwise unspecified; the limitation where non- server column defaults aren’t included in an INSERT FROM SELECT is now lifted and these expressions are rendered as constants into the SELECT statement.

  • [sql] [feature] The UniqueConstraint construct is now included when reflecting a Table object, for databases where this is applicable. 为了以足够的准确度实现这个目标,MySQL和Postgresql现在包含了在反映表,索引和约束时纠正索引重复和唯一约束的功能。In the case of MySQL, there is not actually a “unique constraint” concept independent of a “unique index”, so for this backend UniqueConstraint continues to remain non-present for a reflected Table. For Postgresql, the query used to detect indexes against pg_index has been improved to check for the same construct in pg_constraint, and the implicitly constructed unique index is not included with a reflected Table.

    In both cases, the Inspector.get_indexes() and the Inspector.get_unique_constraints() methods return both constructs individually, but include a new token duplicates_constraint in the case of Postgresql or duplicates_index in the case of MySQL to indicate when this condition is detected. 拉请求礼貌约翰内斯Erdfelt。


  • [sql] [feature] Added new method Select.with_statement_hint() and ORM method Query.with_statement_hint() to support statement-level hints that are not specific to a table.


  • [sql] [feature] The info parameter has been added as a constructor argument to all schema constructs including MetaData, Index, ForeignKey, ForeignKeyConstraint, UniqueConstraint, PrimaryKeyConstraint, CheckConstraint.


  • [sql] [feature] The Table.autoload_with flag now implies that Table.autoload should be True. 请求Malik Diarra提供。


  • [sql] [feature] The Select.limit() and Select.offset() methods now accept any SQL expression, in addition to integer values, as arguments. 通常用于允许传递一个绑定参数,这个参数可以被一个值替代,从而允许SQL查询的Python端缓存。这里的实现完全向后兼容现有的第三方方言,但是那些实现特殊LIMIT / OFFSET系统的方言需要修改才能利用新的功能。限制和偏移也支持“literal_binds”模式,


  • [sql] [changed] The column() and table() constructs are now importable from the “from sqlalchemy” namespace, just like every other Core construct.

  • [sql] [changed] The implicit conversion of strings to text() constructs when passed to most builder methods of select() as well as Query now emits a warning with just the plain string sent. 文本转换仍然正常进行,但是。接受一个没有警告的字符串的唯一方法是像“order_by(),group_by()”这样的“标签引用”方法。这些函数现在将在编译时尝试将单个字符串参数解析为可选择的列或标签表达式;如果没有找到,表达式仍然呈现,但是会再次收到警告。这里的基本原理是,从字符串到文本的隐式转换比现在更加不可预料,用户在传递原始字符串时应该向Core / ORM发送更多方向,以便应该采取什么方向。core_ORM教程已经更新,深入了解如何处理文本。


  • [sql] [bug] Added the native_enum flag to the __repr__() output of Enum, which is mostly important when using it with Alembic autogenerate. 拉请求礼貌Dimitris Theodorou。



  • [sql] [bug] Fixed bug where using a TypeDecorator that implemented a type that was also a TypeDecorator would fail with Python’s “Cannot create a consistent method resolution order (MRO)” error, when any kind of SQL comparison expression were used against an object using this type.



  • [sql] [bug] Fixed issue where the columns from a SELECT embedded in an INSERT, either through the values clause or as a “from select”, would pollute the column types used in the result set produced by the RETURNING clause when columns from both statements shared the same name, leading to potential errors or mis-adaptation when retrieving the returning rows.



  • [sql] [bug] Fixed bug where a fair number of SQL elements within the sql package would fail to __repr__() successfully, due to a missing description attribute that would then invoke a recursion overflow when an internal AttributeError would then re-invoke __repr__().



  • [sql] [bug] An adjustment to table/index reflection such that if an index reports a column that isn’t found to be present in the table, a warning is emitted and the column is skipped. 这可能会发生在一些特殊的系统列情况下,就像在Oracle中观察到的那样。



  • [sql] [bug] Fixed bug in CTE where literal_binds compiler argument would not be always be correctly propagated when one CTE referred to another aliased CTE in a statement.



  • [sql] [bug] Fixed 0.9.7 regression caused by #3067 in conjunction with a mis-named unit test such that so-called “schema” types like Boolean and Enum could no longer be pickled.



  • [sql] [bug] Fix bug in naming convention feature where using a check constraint convention that includes constraint_name would then force all Boolean and Enum types to require names as well, as these implicitly create a constraint, even if the ultimate target backend were one that does not require generation of the constraint such as Postgresql. 这些特定约束的命名约定的机制已被重新组织,以便在DDL编译时完成命名确定,而不是在约束/表构造时完成。

    This change is also backported to: 0.9.7


  • [sql] [bug] Fixed bug in common table expressions whereby positional bound parameters could be expressed in the wrong final order when CTEs were nested in certain ways.

    This change is also backported to: 0.9.7


  • 修正了多值Insert构造的错误,将无法检查给定的字面SQL表达式的第一个以后的值。[sql] [bug]

    This change is also backported to: 0.9.7


  • [sql] [bug] Added a “str()” step to the dialect_kwargs iteration for Python version < 2.6.5, working around the “no unicode keyword arg” bug as these args are passed along as keyword args within some reflection processes.

    This change is also backported to: 0.9.7


  • [sql] [bug] The TypeEngine.with_variant() method will now accept a type class as an argument which is internally converted to an instance, using the same convention long established by other constructs such as Column.

    This change is also backported to: 0.9.7


  • [sql] [bug] The Column.nullable flag is implicitly set to False when that Column is referred to in an explicit PrimaryKeyConstraint for that table. 现在,这种行为与Column本身将Column.primary_key标志设置为True时的行为相匹配,该行为旨在成为一个完全等效的情况¶ T8>



  • [sql] [bug] Fixed bug where the Operators.__and__(), Operators.__or__() and Operators.__invert__() operator overload methods could not be overridden within a custom TypeEngine.Comparator implementation.



  • [sql] [bug] Fixed bug in new DialectKWArgs.argument_for() method where adding an argument for a construct not previously included for any special arguments would fail.



  • [sql] [bug] Fixed regression introduced in 0.9 where new “ORDER BY ” feature from #1068 would not apply quoting rules to the label name as rendered in the ORDER BY.



  • [sql] [bug] Function的导入恢复到sqlalchemy.sql.expression import命名空间,该命名空间在0.9开始时被删除¶ T7>


  • [sql] [bug] Fixed bug in Enum and other SchemaType subclasses where direct association of the type with a MetaData would lead to a hang when events (like create events) were emitted on the MetaData.

    This change is also backported to: 0.9.7, 0.8.7


  • [sql] [bug] Fixed a bug within the custom operator plus TypeEngine.with_variant() system, whereby using a TypeDecorator in conjunction with variant would fail with an MRO error when a comparison operator was used.

    This change is also backported to: 0.9.7, 0.8.7


  • [sql] [bug] Fixed bug in INSERT..FROM SELECT construct where selecting from a UNION would wrap the union in an anonymous (e.g. unlabled) subquery.

    This change is also backported to: 0.9.5, 0.8.7


  • [sql] [bug] Fixed bug where Table.update() and Table.delete() would produce an empty WHERE clause when an empty and_() or or_() or other blank expression were applied. 这与select()的一致。

    This change is also backported to: 0.9.5, 0.8.7


  • [sql] [bug] The multi-values version of Insert.values() has been repaired to work more usefully with tables that have Python- side default values and/or functions, as well as server-side defaults. 现在该功能将使用使用“位置”参数的方言;一个Python可调用也将被单独调用,如同“executemany”风格调用一样;服务器端默认列将不再隐式地接收为第一行显式指定的值,而是拒绝在没有显式值的情况下调用。


  • [sql] [bug] Fixed bug in Table.tometadata() method where the CheckConstraint associated with a Boolean or Enum type object would be doubled in the target table. 复制过程现在跟踪这个约束对象的产生,作为一个类型对象的本地。


  • [sql] [bug] The behavioral contract of the ForeignKeyConstraint.columns collection has been made consistent; this attribute is now a ColumnCollection like that of all other constraints and is initialized at the point when the constraint is associated with a Table.


  • [sql] [bug] The Column.key attribute is now used as the source of anonymous bound parameter names within expressions, to match the existing use of this value as the key when rendered in an INSERT or UPDATE statement. 这允许将Column.key用作“替代”字符串来解决难以转换成绑定参数名称的困难列名称。请注意,在任何情况下,paramstyle都可以在create_engine()上配置,今天大多数DBAPI支持命名和位置样式。


  • [sql] [bug] Fixed the name of the PoolEvents.reset.dbapi_connection parameter as passed to this event; in particular this affects usage of the “named” argument style for this event. 请求Jason Goldberger提供。


  • [sql] [bug] Reversing a change that was made in 0.9, the “singleton” nature of the “constants” null(), true(), and false() has been reverted. 这些函数返回一个“单例”对象的效果是,不管词法用法如何,不同的实例将被视为相同,这尤其会影响SELECT语句的columns子句的呈现。


  • [sql] [bug] [engine] Fixed bug where a “branched” connection, that is the kind you get when you call Connection.connect(), would not share invalidation status with the parent. 分支体系结构已经做了一些调整,以便分支连接在所有的无效状态和操作中都遵循父节点。


  • [sql] [bug] [engine] Fixed bug where a “branched” connection, that is the kind you get when you call Connection.connect(), would not share transaction status with the parent. 分支体系结构已经做了一些调整,以便分支连接按照所有事务状态和操作顺序进行。


  • [sql] [bug] Using Insert.from_select() now implies inline=True on insert(). 这有助于修复INSERT ... FROM SELECT构造无意中编译为支持后端的“隐式返回”的错误,这会在插入零行的INSERT情况下导致破坏(因为隐式返回期望行) ,以及插入多行的INSERT(例如,只有许多行的第一行)情况下的任意返回数据。一个类似的更改也适用于具有多个参数集的INSERT..VALUES;隐式RETURNING将不再为这个语句发出。由于这两个构造都处理可变数量的行,所以ResultProxy.inserted_primary_key存取器不适用。以前,有一个文档说明,有人可能更喜欢使用INSERT..FROM SELECT的inline=True,因为有些数据库不支持返回,因此不能做“隐式”返回,但是没有任何理由INSERT ... FROM SELECT需要在任何情况下隐式返回。如果需要插入数据,则应使用常规的显式Insert.returning()来返回可变数量的结果行。


  • [sql] [enhancement] Custom dialects that implement GenericTypeCompiler can now be constructed such that the visit methods receive an indication of the owning expression object, if any. 任何接受关键字参数(例如**kw)的访问方法在大多数情况下都会接收关键字参数type_expression,并引用该类型所在的表达式对象。对于DDL中的列,方言的编译器类可能需要修改它的get_column_specification()方法来支持这一点。如果在参数签名中提供**kw,则UserDefinedType.get_col_spec()方法也将接收type_expression >


架构¶ T0>

的PostgreSQL ¶ T0>

  • [postgresql] [feature] 增加了对CONCURRENTLY关键字与Postgresql索引的支持,使用postgresql_concurrently建立。请求Iuri de Silvio提出请求。


    Indexes with CONCURRENTLY的索引



  • [postgresql] [feature] [pg8000] 使用pg8000驱动程序添加了“理智的多行计数”支持,主要适用于使用ORM进行版本控制的情况。该功能基于使用的pg8000 1.9.14或更高版本进行版本检测。请求托尼·洛克(Tony Locke)提出请求。



  • [postgresql] [feature] Added kw argument postgresql_regconfig to the ColumnOperators.match() operator, allows the “reg config” argument to be specified to the to_tsquery() function emitted. 请求Jonathan Vanasco提供。

    This change is also backported to: 0.9.7


  • [postgresql] [feature] 通过JSONB增加了对Postgresql JSONB的支持。请求Damian Dimmich请求。

    This change is also backported to: 0.9.7


  • [postgresql] [feature] 在使用pg8000 DBAPI时增加了对AUTOCOMMIT隔离级别的支持。请求托尼·洛克(Tony Locke)提出请求。



  • [postgresql] [feature] 添加了一个新的标志ARRAY.zero_indexes到Postgresql ARRAY类型。当设置为True时,在传递到数据库之前,值为1将被添加到所有数组索引值,从而允许Python样式的基于零的索引和基于PostgreSQL的基于1的索引之间的更好的互操作性。请求礼貌Alexey Terentev。


    References: #2785, pull request bitbucket:18

  • [postgresql] [feature] The PG8000 dialect now supports the create_engine.encoding parameter, by setting up the client encoding on the connection which is then intercepted by pg8000. 请求托尼·洛克(Tony Locke)提出请求。


  • [postgresql] [feature] 增加了对PG8000原生JSONB功能的支持。请求托尼·洛克(Tony Locke)提出请求。


  • [postgresql] [feature] [pypy] 增加了对pypy上psycopg2cffi DBAPI的支持。拉请求礼貌shauns。

    References: #3052, pull request bitbucket:34

  • [postgresql] [feature] 新增了对应用于PostgreSQL 9.4支持的聚合函数的FILTER关键字的支持。拉请求IljaEverilä礼貌。


  • [postgresql] [feature] 已经添加了对物化视图和外部表的反映,以及对Inspector.get_view_names()中物化视图的支持以及新方法PGInspector.get_foreign_table_names()在Postgresql版本的Inspector上可用。请求礼貌Rodrigo Menezes。

    References: #2891, pull request github:128

  • [postgresql] [feature] 在通过Table构造渲染DDL时,增加了对PG表选项TABLESPACE,ON COMMIT,WITH(OUT)OIDS和INHERITS的支持。拉请求礼貌malikdiarra。


  • [postgresql] [feature] Added new method PGInspector.get_enums(), when using the inspector for Postgresql will provide a list of ENUM types. 请求礼貌Ilya Pekelny。


  • [postgresql] [bug] 使用psycopg2修复了对Postgresql UUID类型与ARRAY类型的支持。psycopg2方言现在使用了psycopg2.extras.register_uuid()钩子,以便始终将UUID值作为UUID()对象传递给DBAPI。UUID.as_uuid标志仍然有效,除了psycopg2,我们需要将返回的UUID对象转换回字符串。



  • [postgresql] [bug] Added support for the postgresql.JSONB datatype when using psycopg2 2.5.4 or greater, which features native conversion of JSONB data so that SQLAlchemy’s converters must be disabled; additionally, the newly added psycopg2 extension extras.register_default_jsonb is used to establish a JSON deserializer passed to the dialect via the json_deserializer argument. 还修复了Postgresql集成测试,实际上并没有将JSONB类型与JSON类型相比翻转。拉请求Mateusz Susik。



  • [postgresql] [bug] Repaired the use of the “array_oid” flag when registering the HSTORE type with older psycopg2 versions < 2.4.3, which does not support this flag, as well as use of the native json serializer hook “register_default_json” with user-defined json_deserializer on psycopg2 versions < 2.5, which does not include native json.


  • [postgresql] [bug] Fixed bug where Postgresql dialect would fail to render an expression in an Index that did not correspond directly to a table-bound column; typically when a text() construct was one of the expressions within the index; or could misinterpret the list of expressions if one or more of them were such an expression.



  • [postgresql] [bug] A revisit to this issue first patched in 0.9.5, apparently psycopg2’s .closed accessor is not as reliable as we assumed, so we have added an explicit check for the exception messages “SSL SYSCALL error: Bad file descriptor” and “SSL SYSCALL error: EOF detected” when detecting an is-disconnect scenario. 我们将继续咨询psycopg2的connection.closed作为第一个检查。



  • [postgresql] [bug] Fixed bug where Postgresql JSON type was not able to persist or otherwise render a SQL NULL column value, rather than a JSON-encoded 'null'. 为了支持这种情况,更改如下:

    • 现在可以指定null()值,这将始终导致产生该语句的NULL值。
    • 添加了一个新的参数JSON.none_as_null,当True表示Python None值应该作为SQL NULL执行,而不是JSON编码'null'




  • [postgresql] [bug] DBAPI错误的异常包装系统现在可以容纳非标准的DBAPI异常,例如psycopg2 TransactionRollbackError。这些异常现在将使用sqlalchemy.exc中最接近的可用子类进行引发,如果是TransactionRollbackError,sqlalchemy.exc.OperationalError



  • [postgresql] [bug] Fixed bug in postgresql.array object where comparison to a plain Python list would fail to use the correct array constructor. 拉请求礼貌Andrew。



  • [postgresql] [bug] 为函数添加了一个支持的FunctionElement.alias()方法。 func构造。以前,这个方法的行为是未定义的。当前的行为模仿0.9.4之前的行为,也就是说,该函数被转换为具有给定别名的单列FROM子句,其中列本身是匿名命名的。



  • [postgresql] [bug] [pg8000] 修正了0.9.5版本中新的pg8000隔离级别功能导致的错误,其中引擎级别的隔离级别参数会在连接时产生错误¶ t2 >

    This change is also backported to: 0.9.7


  • [postgresql] [bug] The psycopg2 .closed accessor is now consulted when determining if an exception is a “disconnect” error; ideally, this should remove the need for any other inspection of the exception message to detect disconnect, however we will leave those existing messages in place as a fallback. 这应该能够处理像“SSL EOF”条件的新情况。拉德要求礼貌德克米勒。



  • [postgresql] [bug] hashable=False标志添加到PG HSTORE类型中,ORM跳过在混合列/实体列表中请求ORM映射的HSTORE列时“散列”。补丁礼貌GunnlaugurÞórBriem。

    This change is also backported to: 0.9.5, 0.8.7


  • [postgresql] [bug] 添加了一个新的“断开”消息“连接已经意外关闭”。这似乎与更新版本的SSL有关。请求Antti Haapala提供。

    This change is also backported to: 0.9.5, 0.8.7


  • [postgresql] [bug] The Postgresql postgresql.ENUM type will emit a DROP TYPE instruction when a plain table.drop() is called, assuming the object is not associated directly with a MetaData object. 为了适应多个表之间共享的枚举类型的用例,类型应该直接与MetaData对象关联;在这种情况下,类型只能在元数据级创建,或者直接创建。一般来说,Postgresql枚举类型的创建/删除规则已被高度重构。


  • [postgresql] [bug] The PGDialect.has_table() method will now query against pg_catalog.pg_table_is_visible(c.oid), rather than testing for an exact schema match, when the schema name is None; this so that the method will also illustrate that temporary tables are present. 请注意,这是一个行为改变,因为Postgresql允许非临时表静静地覆盖同名的现有临时表,所以这改变了checkfirst在该异常情况下的行为。


  • [postgresql] [enhancement] 将新的类型postgresql.OID添加到Postgresql方言中。尽管“oid”通常是PG中的私有类型,但在现代版本中并未公开,但有一些PG用例,例如可能暴露这些类型的大型对象支持,以及某些用户报告的模式反射用例。 ¶ T0>



MySQL的¶ T0>

  • [mysql] [feature] The MySQL dialect now renders TIMESTAMP with NULL / NOT NULL in all cases, so that MySQL 5.6.6 with the explicit_defaults_for_timestamp flag enabled will will allow TIMESTAMP to continue to work as expected when nullable=False. 现有的应用程序不受影响,因为SQLAlchemy总是为nullable=True的TIMESTAMP列发出NULL。


  • [mysql] [feature] 在Python 2中将MySQLdb和Pymysql的“supports_unicode_statements”标志更新为True。这是指SQL语句本身,而不是参数,并影响使用非ASCII字符的表和列名称等问题。这些驱动程序似乎都支持Python 2 Unicode对象,在现代版本中没有问题。


  • [mysql] [bug] Added a version check to the MySQLdb dialect surrounding the check for ‘utf8_bin’ collation, as this fails on MySQL server < 5.0.



  • [mysql] [bug] [mysqlconnector] Mysqlconnector as of version 2.0, probably as a side effect of the python 3 merge, now does not expect percent signs (e.g. as used as the modulus operator and others) to be doubled, even when using the “pyformat” bound parameter format (this change is not documented by Mysqlconnector). 当检测模运算符是否应该呈现为%%%时,方言现在检查py2k和小于版本2.0的mysql连接器。


  • [mysql] [bug] [mysqlconnector] Unicode SQL is now passed for MySQLconnector version 2.0 and above; for Py2k and MySQL < 2.0, strings are encoded.


  • [mysql] [bug] MySQL error 2014 “commands out of sync” appears to be raised as a ProgrammingError, not OperationalError, in modern MySQL-Python versions; all MySQL error codes that are tested for “is disconnect” are now checked within OperationalError and ProgrammingError regardless.

    This change is also backported to: 0.9.7, 0.8.7


  • [mysql] [bug] Fixed bug where column names added to mysql_length parameter on an index needed to have the same quoting for quoted names in order to be recognized. 该修复使得引号是可选的,但是也提供了与使用变通方法的向后兼容的旧行为。

    This change is also backported to: 0.9.5, 0.8.7


  • [mysql] [bug] 增加了对使用等号来反映表的索引包括KEY_BLOCK_SIZE的支持。拉请求礼貌肖恩McGivern。

    This change is also backported to: 0.9.5, 0.8.7


  • [mysql] [bug] 现在,MySQL方言支持将CAST构造为TypeDecorator对象的类型。

  • [mysql] [bug] 在MySQL不支持CAST的类型上使用cast() MySQL仅支持数据类型子集的CAST。SQLAlchemy很长一段时间在MySQL中省略了不支持类型的CAST。现在我们不想改变这个,我们发出一个警告来表明它已经发生了。A warning is also emitted when a CAST is used with an older MySQL version (< 4) that doesn’t support CAST at all, it’s skipped in this case as well.


  • [mysql] [bug] The mysql.SET type has been overhauled to no longer assume that the empty string, or a set with a single empty string value, is in fact a set with a single empty string; instead, this is by default treated as the empty set. In order to handle persistence of a mysql.SET that actually wants to include the blank value '' as a legitimate value, a new bitwise operational mode is added which is enabled by the mysql.SET.retrieve_as_bitwise flag, which will persist and retrieve values unambiguously using their bitflag positioning. 存储和检索本地不转换unicode的驱动程序配置的unicode值也会被修复。


  • [mysql] [bug] The ColumnOperators.match() operator is now handled such that the return type is not strictly assumed to be boolean; it now returns a Boolean subclass called MatchType. 在Python表达式中使用时,类型仍然会产生布尔行为,但方言可以在结果时覆盖它的行为。在MySQL的情况下,MATCH运算符通常用在表达式中的布尔上下文中,如果实际查询匹配表达式的值,则返回浮点值;此值与SQLAlchemy的基于C的布尔处理器不兼容,所以MySQL的结果集行为现在遵循Float类型。还增加了新的操作符对象notmatch_op,以便更好地允许方言定义匹配操作的否定。


  • [mysql] [bug] MySQL boolean symbols “true”, “false” work again. 0.9 #2682中的变化不允许MySQL方言在“IS”/“IS NOT”的上下文中使用“true”和“false”符号,但MySQL甚至支持这种语法尽管它没有布尔类型。MySQL remains “non native boolean”, but the true() and false() symbols again produce the keywords “true” and “false”, so that an expression like column.is_(true()) again works on MySQL.


  • [mysql] [bug] The MySQL dialect will now disable ConnectionEvents.handle_error() events from firing for those statements which it uses internally to detect if a table exists or not. 这是通过使用执行选项skip_user_error_events来实现的,该选项为该执行的范围禁用句柄错误事件。通过这种方式,重写异常的用户代码不需要担心偶尔需要捕获SQLAlchemy特定异常的MySQL方言或其他方言。

  • [mysql] [bug] 为MySQLconnector更改了“raise_on_warnings”的默认值为False。由于某种原因,这被设置为True。不幸的是,“缓冲”标志必须保持为True,因为MySQL连接器不允许关闭游标,除非所有结果都被完全获取。


  • [mysql] [change] The gaerdbms dialect is no longer necessary, and emits a deprecation warning. Google现在建议直接使用MySQLdb方言。



源码¶ T0>

  • [sqlite] [feature] 新增了对SQLite的部分索引(例如使用WHERE子句)的支持。请求Kai Groner提出的请求。


    Partial Indexes



  • [sqlite] [feature] 为SQLCipher后端添加了一个新的SQLite后端。这个后端提供使用pysqlcipher Python驱动程序的加密SQLite数据库,这与pysqlite驱动程序非常相似。




  • [sqlite] [bug] When selecting from a UNION using an attached database file, the pysqlite driver reports column names in cursor.description as ‘dbname.tablename.colname’, instead of ‘tablename.colname’ as it normally does for a UNION (note that it’s supposed to just be ‘colname’ for both, but we work around it). 这里的列转换逻辑已被调整来检索最右边的标记,而不是第二个标记,所以它在两种情况下都起作用。解决方法:Tony Roberts。



  • [sqlite] [bug] Fixed a SQLite join rewriting issue where a subquery that is embedded as a scalar subquery such as within an IN would receive inappropriate substitutions from the enclosing query, if the same table were present inside the subquery as were in the enclosing query such as in a joined inheritance scenario.

    This change is also backported to: 0.9.7


  • [sqlite] [bug] UNIQUE and FOREIGN KEY constraints are now fully reflected on SQLite both with and without names. 以前,外键名称被忽略,未命名的唯一约束被忽略。感谢Jon Nelson的帮助。


  • [sqlite] [bug] The SQLite dialect, when using the sqlite.DATE, sqlite.TIME, or sqlite.DATETIME types, and given a storage_format that only renders numbers, will render the types in DDL as DATE_CHAR, TIME_CHAR, and DATETIME_CHAR, so that despite the lack of alpha characters in the values, the column will still deliver the “text affinity”. 通常这不是必需的,因为默认存储格式中的文本值已经暗示了文本。


    Date and Time Types


  • [sqlite] [bug] SQLite now supports reflection of unique constraints from temp tables; previously, this would fail with a TypeError. 拉请求礼貌约翰内斯Erdfelt。


    SQLite/Oracle have distinct methods for temporary table/view name reporting - changes regarding SQLite temporary table and view reflection.


  • [sqlite] [bug] 添加了Inspector.get_temp_table_names()Inspector.get_temp_view_names();目前,只有SQLite和Oracle方言支持这些方法。The return of temporary table and view names has been removed from SQLite and Oracle’s version of Inspector.get_table_names() and Inspector.get_view_names(); other database backends cannot support this information (such as MySQL), and the scope of operation is different in that the tables can be local to a session and typically aren’t supported in remote schemas.



  • [mssql] [feature] Enabled “multivalues insert” for SQL Server 2008. 拉尔请求礼貌伟业Cervin。同样扩展了对“IDENTITY INSERT”模式的检查,以便在语句的VALUE子句中存在身份密钥时包含

    This change is also backported to: 0.9.7


  • [mssql] [feature] SQL Server 2012 now recommends VARCHAR(max), NVARCHAR(max), VARBINARY(max) for large text/binary types. MSSQL方言现在将基于版本检测以及新的deprecate_large_types标志来尊重这一点。


  • [mssql] [changed] 使用pyodbc时,SQL Server的基于主机名的连接格式将不再指定默认的“驱动程序名称”,并且如果缺少该驱动程序名称,则会发出警告。SQL Server的最佳驱动程序名称经常更改并且是平台,因此基于主机名的连接需要指定此名称。基于DSN的连接是首选。


  • [mssql] [bug] 修复了pymssql方言中的版本字符串检测问题,与Microsoft SQL Azure一起使用,它将“SQL Server”一词改为“SQL Azure”。¶ t2 >



  • [mssql] [bug] Revised the query used to determine the current default schema name to use the database_principal_id() function in conjunction with the sys.database_principals view so that we can determine the default schema independently of the type of login in progress (e.g., SQL Server, Windows, etc).



  • [mssql] [bug] Added statement encoding to the “SET IDENTITY_INSERT” statements which operate when an explicit INSERT is being interjected into an IDENTITY column, to support non-ascii table identifiers on drivers such as pyodbc + unix + py2k that don’t support unicode statements.

    This change is also backported to: 0.9.7, 0.8.7

  • [mssql] [bug] In the SQL Server pyodbc dialect, repaired the implementation for the description_encoding dialect parameter, which when not explicitly set was preventing cursor.description from being parsed correctly in the case of result sets that contained names in alternate encodings. 这个参数不需要继续。

    This change is also backported to: 0.9.7, 0.8.7


预言¶ T0>

  • [oracle] [feature] 通过将?service_name=<name>传递给URL,增加了对特定服务名称的cx_oracle连接的支持,而不是tns名称。拉请求SławomirEhlert。


  • [oracle] [feature] New Oracle DDL features for tables, indexes: COMPRESS, BITMAP. Gabor Gombas供图。

  • [oracle] [feature] Added support for CTEs under Oracle. 这包括对别名语法的一些调整,以及一个新的CTE特性CTE.suffix_with(),这对于向CTE中添加特定的Oracle专用指令很有用。


  • [oracle] [feature] 增加了对Oracle表选项ON COMMIT的支持。

  • [oracle] [bug] Fixed long-standing bug in Oracle dialect where bound parameter names that started with numbers would not be quoted, as Oracle doesn’t like numerics in bound parameter names.



  • [oracle] [bug] [tests] Fixed bug in oracle dialect test suite where in one test, ‘username’ was assumed to be in the database URL, even though this might not be the case.

    This change is also backported to: 0.9.7


  • [oracle] [bug] An alias name will be properly quoted when referred to using the %(name)s token inside the Select.with_hint() method. 以前,Oracle后端没有实现这个引用。

杂项¶ T0>

  • [feature] [examples] 添加了一个新示例,说明使用最新关系功能的物化路径。Jack Zhou提供的例子。



  • [feature] [ext] 添加了一个新的扩展套件sqlalchemy.ext.baked这个简单但不同寻常的系统可以显着节省Python构建和处理orm Query对象,从查询构建到渲染字符串SQL语句。


    Baked Queries


  • [feature] [examples] 一组新的示例,致力于从多个角度详细研究SQLAlchemy ORM和Core以及DBAPI的性能。该套件在一个容器中运行,该容器通过控制台输出以及通过RunSnake工具以图形方式提供内置的分析显示。



  • [feature] [ext] The sqlalchemy.ext.automap extension will now set cascade="all, delete-orphan" automatically on a one-to-many relationship/backref where the foreign key is detected as containing one or more non-nullable columns. 这个参数出现在传递给automap.generate_relationship()的关键字中,并且仍然可以被覆盖。Additionally, if the ForeignKeyConstraint specifies ondelete="CASCADE" for a non-nullable or ondelete="SET NULL" for a nullable set of columns, the argument passive_deletes=True is also added to the relationship. 请注意,并非所有的后端都支持ondelete的反射,但后端包括Postgresql和MySQL。


  • [removed] Drizzle方言已从Core中移除;它现在可以作为sqlalchemy-drizzle,一个独立的第三方方言。方言仍然基于SQLAlchemy中存在的MySQL方言。

  • [bug] [ext] [py3k] Fixed bug where the association proxy list class would not interpret slices correctly under Py3K. 请求Gilles Dartiguelongue提供。



  • [bug] [examples] 更新了Versioning with a History Table的版本控制,以便将映射列重新映射为匹配列名称以及列组;特别是,这允许在历史映射中以相同方式映射显式分组在相同列名称的已连接继承场景中的列,避免在0.9系列中添加关于该模式的警告,并允许相同的属性键¶ T4>


  • [bug] [examples] Fixed a bug in the examples/generic_assocaitions/discriminator_on_association.py example, where the subclasses of AddressAssociation were not being mapped as “single table inheritance”, leading to problems when trying to use the mappings further.


  • [bug] [declarative] Fixed an unlikely race condition observed in some exotic end-user setups, where the attempt to check for “duplicate class name” in declarative would hit upon a not-totally-cleaned-up weak reference related to some other class being removed; the check here now ensures the weakref still references an object before calling upon it further.



  • [bug] [ext] Fixed bug in ordering list where the order of items would be thrown off during a collection replace event, if the reorder_on_append flag were set to True. 该修复确保排序列表仅影响与该对象显式关联的列表。



  • [bug] [ext] Fixed bug where ext.mutable.MutableDict failed to implement the update() dictionary method, thus not catching changes. 拉请求马特Chisholm。


  • [bug] [ext] Fixed bug where a custom subclass of ext.mutable.MutableDict would not show up in a “coerce” operation, and would instead return a plain ext.mutable.MutableDict. 拉请求马特Chisholm。


  • [bug] [pool] Fixed bug in connection pool logging where the “connection checked out” debug logging message would not emit if the logging were set up using logging.setLevel(), rather than using the echo_pool flag. 已经添加了测试来声明这个日志记录。这是在0.9.0中引入的回归。



  • [bug] [tests] Fixed bug where “python setup.py test” wasn’t calling into distutils appropriately, and errors would be emitted at the end of the test suite.

    This change is also backported to: 0.9.7

  • [bug] [declarative] Fixed bug when the declarative __abstract__ flag was not being distinguished for when it was actually the value False. __abstract__标志需要在正在测试的级别上进行真实值计算。

    This change is also backported to: 0.9.7


  • [bug] [testsuite] In public test suite, shanged to use of String(40) from less-supported Text in StringTest.test_literal_backslashes. Pullreq礼貌Jan.



  • [bug] [tests] [py3k] 在运行测试时,纠正涉及imp模块和Python 3.3或更高版本的一些弃用警告。拉请求马特Chisholm。


    References: #2830, pull request bitbucket:2830

  • [bug] [declarative] The __mapper_args__ dictionary is copied from a declarative mixin or abstract class when accessed, so that modifications made to this dictionary by declarative itself won’t conflict with that of other mappings. 关于version_id_colpolymorphic_on参数的字典被修改,用正式映射到本地类/表的那个字段替换其中的字段。¶ t4 >

    This change is also backported to: 0.9.5, 0.8.7


  • [bug] [ext] Fixed bug in mutable extension where MutableDict did not report change events for the setdefault() dictionary operation.

    This change is also backported to: 0.9.5, 0.8.7


  • [bug] [ext] Fixed bug where MutableDict.setdefault() didn’t return the existing or new value (this bug was not released in any 0.8 version). 请求托马斯·赫维(ThomasHervé)提供。

    This change is also backported to: 0.9.5, 0.8.7

    References: #3093, #3051, pull request bitbucket:24