SqlAlchemy 2.0 中文文档(五十九)(6)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: SqlAlchemy 2.0 中文文档(五十九)

SqlAlchemy 2.0 中文文档(五十九)(5)https://developer.aliyun.com/article/1563151


1.4.6

Released: April 6, 2021

orm

  • [orm] [bug] [regression]
    Fixed regression where a deprecated form of Query.join() were used, passing a series of entities to join from without any ON clause in a single Query.join() call, would fail to function correctly.
    References: #6203
  • [orm] [bug] [regression]
    Fixed critical regression where the Query.yield_per() method in the ORM would set up the internal Result to yield chunks at a time, however made use of the new Result.unique() method which uniques across the entire result. This would lead to lost rows since the ORM is using id(obj) as the uniquing function, which leads to repeated identifiers for new  objects as already-seen objects are garbage collected. 1.3’s behavior  here was to “unique” across each chunk, which does not actually produce  “uniqued” results when results are yielded in chunks. As the Query.yield_per() method is already explicitly disallowed when joined eager loading is in  place, which is the primary rationale for the “uniquing” feature, the  “uniquing” feature is now turned off entirely when Query.yield_per() is used.
    This regression only applies to the legacy Query object; when using 2.0 style execution, “uniquing” is not automatically  applied. To prevent the issue from arising from explicit use of Result.unique(), an error is now raised if rows are fetched from a “uniqued” ORM-level Result if any yield per API is also in use, as the purpose of yield_per is to allow for arbitrarily large numbers of rows, which cannot be  uniqued in memory without growing the number of entries to fit the  complete result size.
    References: #6206

sql

  • [sql] [bug] [mssql] [oracle] [regression]
    Fixed further regressions in the same area as that of #6173 released in 1.4.5, where a “postcompile” parameter, again most  typically those used for LIMIT/OFFSET rendering in Oracle and SQL  Server, would fail to be processed correctly if the same parameter  rendered in multiple places in the statement.
    References: #6202
  • [sql] [bug]
    Executing a Subquery using Connection.execute() is deprecated and will emit a deprecation warning; this use case was an  oversight that should have been removed from 1.4. The operation will  now execute the underlying Select object directly for backwards compatibility. Similarly, the CTE class is also not appropriate for execution. In 1.3, attempting to  execute a CTE would result in an invalid “blank” SQL statement being  executed; since this use case was not working it now raises ObjectNotExecutableError. Previously, 1.4 was attempting to execute the CTE as a statement however it was working only erratically.
    References: #6204

schema

  • [schema] [bug]
    The Table object now raises an informative error message if it is instantiated without passing at least the Table.name and Table.metadata arguments positionally. Previously, if these were passed as keyword  arguments, the object would silently fail to initialize correctly.
    This change is also backported to: 1.3.25
    References: #6135

mypy

  • [mypy] [bug]
    Applied a series of  refactorings and fixes to accommodate for Mypy “incremental” mode across  multiple files, which previously was not taken into account. In this  mode the Mypy plugin has to accommodate Python datatypes expressed in  other files coming in with less information than they have on a direct  run.
    Additionally, a new decorator declarative_mixin() is added, which is necessary for the Mypy plugin to be able to  definifitely identify a Declarative mixin class that is otherwise not  used inside a particular Python file.
    See also
    Using @declared_attr and Declarative Mixins
    References: #6147
  • [mypy] [bug]
    Fixed  issue where the Mypy plugin would fail to interpret the  “collection_class” of a relationship if it were a callable and not a  class. Also improved type matching and error reporting for  collection-oriented relationships.
    References: #6205

asyncio

  • [asyncio] [usecase] [postgresql]
    Added accessors .sqlstate and synonym .pgcode to the .orig attribute of the SQLAlchemy exception class raised by the asyncpg DBAPI  adapter, that is, the intermediary exception object that wraps on top  of that raised by the asyncpg library itself, but below the level of the  SQLAlchemy dialect.
    References: #6199

1.4.5

Released: April 2, 2021

orm

  • [orm] [bug] [regression]
    Fixed regression where the joinedload() loader strategy would not successfully joinedload to a mapper that is mapper against a CTE construct.
    References: #6172
  • [orm] [bug] [regression]
    Scaled back the warning message added in #5171 to not warn for overlapping columns in an inheritance scenario where a  particular relationship is local to a subclass and therefore does not  represent an overlap.
    References: #6171

sql

  • [sql] [bug] [postgresql]
    Fixed bug in new FunctionElement.render_derived() feature where column names rendered out explicitly in the alias SQL  would not have proper quoting applied for case sensitive names and other  non-alphanumeric names.
    References: #6183
  • [sql] [bug] [regression]
    Fixed regression where use of the Operators.in_() method with a Select object against a non-table-bound column would produce an AttributeError, or more generally using a ScalarSelect that has no datatype in a binary expression would produce invalid state.
    References: #6181
  • [sql] [bug]
    Added a new flag to the Dialect class called Dialect.supports_statement_cache.  This flag now needs to be present directly on a dialect class in order  for SQLAlchemy’s query cache to take effect for that dialect. The  rationale is based on discovered issues such as #6173 revealing that dialects which hardcode literal values from the compiled  statement, often the numerical parameters used for LIMIT / OFFSET, will  not be compatible with caching until these dialects are revised to use  the parameters present in the statement only. For third party dialects  where this flag is not applied, the SQL logging will show the message  “dialect does not support caching”, indicating the dialect should seek  to apply this flag once they have verified that no per-statement literal  values are being rendered within the compilation phase.
    See also
    Caching for Third Party Dialects
    References: #6184

schema

  • [schema] [bug]
    Introduce a new parameter Enum.omit_aliases in Enum type allow filtering aliases when using a pep435 Enum. Previous  versions of SQLAlchemy kept aliases in all cases, creating database enum  type with additional states, meaning that they were treated as  different values in the db. For backward compatibility this flag  defaults to False in the 1.4 series, but will be switched to True in a future version. A deprecation warning is raise if this flag is not specified and the passed enum contains aliases.
    References: #6146

mypy

  • [mypy] [bug]
    Fixed issue in mypy plugin where newly added support for as_declarative() needed to more fully add the DeclarativeMeta class to the mypy interpreter’s state so that it does not result in a  name not found error; additionally improves how global names are setup  for the plugin including the Mapped name.
    References: #sqlalchemy/sqlalchemy2-stubs/#14

asyncio

  • [asyncio] [bug]
    Fixed issue where the asyncio extension could not be loaded if running Python 3.6 with the backport library of contextvars installed.
    References: #6166

postgresql

  • [postgresql] [bug] [regression]
    Fixed regression caused by #6023 where the PostgreSQL cast operator applied to elements within an ARRAY when using psycopg2 would fail to use the correct type in the case that  the datatype were also embedded within an instance of the Variant adapter.
    Additionally, repairs support for the correct CREATE TYPE to be emitted when using a Variant(ARRAY(some_schema_type)).
    This change is also backported to: 1.3.25
    References: #6182
  • [postgresql] [bug]
    Fixed typo in the fix for #6099 released in 1.4.4 that completely prevented this change from working  correctly, i.e. the error message did not match what was actually  emitted by pg8000.
    References: #6099
  • [postgresql] [bug]
    Fixed issue where the PostgreSQL PGInspector, when generated against an Engine, would fail for .get_enums(), .get_view_names(), .get_foreign_table_names() and .get_table_oid() when used against a “future” style engine and not the connection directly.
    References: #6170

mysql

  • [mysql] [bug] [regression]
    Fixed  regression in the MySQL dialect where the reflection query used to  detect if a table exists would fail on very old MySQL 5.0 and 5.1  versions.
    References: #6163

mssql

  • [mssql] [bug]
    Fixed a regression in MSSQL 2012+ that prevented the order by clause to be rendered when offset=0 is used in a subquery.
    References: #6163

oracle

  • [oracle] [bug] [regression]
    Fixed  critical regression where the Oracle compiler would not maintain the  correct parameter values in the LIMIT/OFFSET for a select due to a  caching issue.
    References: #6173

1.4.4

Released: March 30, 2021

orm

  • [orm] [bug]
    Fixed critical issue in the new PropComparator.and_() feature where loader strategies that emit secondary SELECT statements such as selectinload() and lazyload() would fail to accommodate for bound parameters in the user-defined  criteria in terms of the current statement being executed, as opposed to  the cached statement, causing stale bound values to be used.
    This also adds a warning for the case where an object that uses lazyload() in conjunction with PropComparator.and_() is attempted to be serialized; the loader criteria cannot reliably be  serialized and deserialized and eager loading should be used for this  case.
    References: #6139
  • [orm] [bug] [regression]
    Fixed missing method Session.get() from the ScopedSession interface.
    References: #6144

engine

  • [engine] [usecase]
    Modified the context manager used by Transaction so that an “already detached” warning is not emitted by the ending of  the context manager itself, if the transaction were already manually  rolled back inside the block. This applies to regular transactions,  savepoint transactions, and legacy “marker” transactions. A warning is  still emitted if the .rollback() method is called explicitly more than once.
    References: #6155
  • [engine] [bug]
    Repair wrong arguments to exception handling method in CursorResult.
    References: #6138

postgresql

  • [postgresql] [bug] [reflection]
    Fixed  issue in PostgreSQL reflection where a column expressing “NOT NULL”  will supersede the nullability of a corresponding domain.
    This change is also backported to: 1.3.24
    References: #6161
  • [postgresql] [bug]
    Modified the is_disconnect() handler for the pg8000 dialect, which now accommodates for a new InterfaceError emitted by pg8000 1.19.0. Pull request courtesy Hamdi Burak Usul.
    References: #6099

misc

  • [misc] [bug]
    Adjusted the usage of the importlib_metadata library for loading setuptools entrypoints in order to accommodate for some deprecation changes.

1.4.3

Released: March 25, 2021

orm

  • [orm] [bug]
    Fixed a bug where python 2.7.5 (default on CentOS 7) wasn’t able to import sqlalchemy, because on this version of Python exec "statement" and exec("statement") do not behave the same way. The compatibility exec_() function was used instead.
    References: #6069
  • [orm] [bug]
    Fixed bug where ORM queries using a correlated subquery in conjunction with column_property() would fail to correlate correctly to an enclosing subquery or to a CTE when Select.correlate_except() were used in the property to control correlation, in cases where the  subquery contained the same selectables as ones within the correlated  subquery that were intended to not be correlated.
    References: #6060
  • [orm] [bug]
    Fixed  bug where combinations of the new “relationship with criteria” feature  could fail in conjunction with features that make use of the new “lambda  SQL” feature, including loader strategies such as selectinload and  lazyload, for more complicated scenarios such as polymorphic loading.
    References: #6131
  • [orm] [bug]
    Repaired support so that the ClauseElement.params() method can work correctly with a Select object that includes joins across ORM relationship structures, which is a new feature in 1.4.
    References: #6124
  • [orm] [bug]
    Fixed issue where a “removed in 2.0” warning were generated internally by the relationship loader mechanics.
    References: #6115

orm declarative

  • [orm] [declarative] [bug] [regression]
    Fixed regression where the .metadata attribute on a per class level would not be honored, breaking the use case of per-class-hierarchy MetaData for abstract declarative classes and mixins.
    See also
    metadata
    References: #6128

engine

  • [engine] [bug] [regression]
    Restored the ResultProxy name back to the sqlalchemy.engine namespace. This name refers to the LegacyCursorResult object.
    References: #6119

schema

  • [schema] [bug]
    Adjusted the logic that emits DROP statements for Sequence objects among the dropping of multiple tables, such that all Sequence objects are dropped after all tables, even if the given Sequence is related only to a Table object and not directly to the overall MetaData object. The use case supports the same Sequence being associated with more than one Table at a time.
    This change is also backported to: 1.3.24
    References: #6071

mypy

  • [mypy] [bug]
    Added support for the Mypy extension to correctly interpret a declarative base class that’s generated using the as_declarative() function as well as the registry.as_declarative_base() method.
  • [mypy] [bug]
    Fixed bug in Mypy plugin where the Python type detection for the Boolean column type would produce an exception; additionally implemented support for Enum, including detection of a string-based enum vs. use of Python enum.Enum.
    References: #6109

postgresql

  • [postgresql] [bug] [types]
    Adjusted  the psycopg2 dialect to emit an explicit PostgreSQL-style cast for bound  parameters that contain ARRAY elements. This allows the full range of  datatypes to function correctly within arrays. The asyncpg dialect  already generated these internal casts in the final statement. This also  includes support for array slice updates as well as the  PostgreSQL-specific ARRAY.contains() method.
    This change is also backported to: 1.3.24
    References: #6023
  • [postgresql] [bug] [reflection]
    Fixed reflection of identity columns in tables with mixed case names in PostgreSQL.
    References: #6129

sqlite

  • [sqlite] [feature] [asyncio]
    Added support for the aiosqlite database driver for use with the SQLAlchemy asyncio extension.
    See also
    Aiosqlite
    References: #5920
  • [sqlite] [bug] [regression]
    Repaired the pysqlcipher dialect to connect correctly which had regressed in 1.4, and added test  + CI support to maintain the driver in working condition. The dialect  now imports the sqlcipher3 module for Python 3 by default before falling back to pysqlcipher3 which is documented as now being unmaintained.
    See also
    Pysqlcipher
    References: #5848

1.4.2

Released: March 19, 2021

orm

  • [orm] [usecase] [dataclasses]
    Added support for the declared_attr object to work in the context of dataclass fields.
    See also
    Using Declarative Mixins with pre-existing dataclasses
    References: #6100
  • [orm] [bug] [dataclasses]
    Fixed  issue in new ORM dataclasses functionality where dataclass fields on an  abstract base or mixin that contained column or other mapping  constructs would not be mapped if they also included a “default” key  within the dataclasses.field() object.
    References: #6093
  • [orm] [bug] [regression]
    Fixed regression where the Query.selectable accessor, which is a synonym for Query.__clause_element__(), got removed, it’s now restored.
    References: #6088
  • [orm] [bug] [regression]
    Fixed  regression where use of an unnamed SQL expression such as a SQL  function would raise a column targeting error if the query itself were  using joinedload for an entity and was also being wrapped in a subquery  by the joinedload eager loading process.
    References: #6086
  • [orm] [bug] [regression]
    Fixed regression where the Query.filter_by() method would fail to locate the correct source entity if the Query.join() method had been used targeting an entity without any kind of ON clause.
    References: #6092
  • [orm] [bug] [regression]
    Fixed regression where the SQL compilation of a Function would not work correctly if the object had been “annotated”, which is  an internal memoization process used mostly by the ORM. In particular it  could affect ORM lazy loads which make greater use of this feature in  1.4.
    References: #6095
  • [orm] [bug]
    Fixed regression where the ConcreteBase would fail to map at all when a mapped column name overlapped with the  discriminator column name, producing an assertion error. The use case  here did not function correctly in 1.3 as the polymorphic union would  produce a query that ignored the discriminator column entirely, while  emitting duplicate column warnings. As 1.4’s architecture cannot easily  reproduce this essentially broken behavior of 1.3 at the select() level right now, the use case now raises an informative error message instructing the user to use the .ConcreteBase._concrete_discriminator_name attribute to resolve the conflict. To assist with this configuration, .ConcreteBase._concrete_discriminator_name may be placed on the base class only where it will be automatically used by subclasses; previously this was not the case.
    References: #6090

engine

  • [engine] [bug] [regression]
    Restored top level import for sqlalchemy.engine.reflection. This ensures that the base Inspector class is properly registered so that inspect() works for third party dialects that don’t otherwise import this package.

sql

  • [sql] [bug] [regression]
    Fixed issue where using a func that includes dotted packagenames would fail to be cacheable by the SQL  caching system due to a Python list of names that needed to be a tuple.
    References: #6101
  • [sql] [bug] [regression]
    Fixed regression in the case() construct, where the “dictionary” form of argument specification failed  to work correctly if it were passed positionally, rather than as a  “whens” keyword argument.
    References: #6097

mypy

  • [mypy] [bug]
    Fixed issue in MyPy extension which crashed on detecting the type of a Column if the type were given with a module prefix like sa.Integer().
    References: #sqlalchemy/sqlalchemy2-stubs/2

postgresql

  • [postgresql] [usecase]
    Rename the column name used by a reflection query that used a reserved word in some postgresql compatible databases.
    References: #6982

1.4.1

Released: March 17, 2021

orm

  • [orm] [bug] [regression]
    Fixed regression where producing a Core expression construct such as select() using ORM entities would eagerly configure the mappers, in an effort to maintain compatibility with the Query object which necessarily does this to support many backref-related legacy cases. However, core select() constructs are also used in mapper configurations and such, and to that  degree this eager configuration is more of an inconvenience, so eager  configure has been disabled for the select() and other Core constructs in the absence of ORM loading types of functions such as Load.
    The change maintains the behavior of Query so that backwards compatibility is maintained. However, when using a select() in conjunction with ORM entities, a “backref” that isn’t explicitly  placed on one of the classes until mapper configure time won’t be  available unless configure_mappers() or the newer configure() has been called elsewhere. Prefer using relationship.back_populates for more explicit relationship configuration which does not have the eager configure requirement.
    References: #6066
  • [orm] [bug] [regression]
    Fixed  a critical regression in the relationship lazy loader where the SQL  criteria used to fetch a related many-to-one object could go stale in  relation to other memoized structures within the loader if the mapper  had configuration changes, such as can occur when mappers are late  configured or configured on demand, producing a comparison to None and  returning no object. Huge thanks to Alan Hamlett for their help tracking  this down late into the night.
    References: #6055
  • [orm] [bug] [regression]
    Fixed regression where the Query.exists() method would fail to create an expression if the entity list of the Query were an arbitrary SQL column expression.
    References: #6076
  • [orm] [bug] [regression]
    Fixed regression where calling upon Query.count() in conjunction with a loader option such as joinedload() would fail to ignore the loader option. This is a behavior that has always been very specific to the Query.count() method; an error is normally raised if a given Query has options that don’t apply to what it is returning.
    References: #6052
  • [orm] [bug] [regression]
    Fixed regression in Session.identity_key(),  including that the method and related methods were not covered by any  unit test as well as that the method contained a typo preventing it from  functioning correctly.
    References: #6067

orm declarative

  • [orm] [declarative] [bug] [regression]
    Fixed  bug where user-mapped classes that contained an attribute named  “registry” would cause conflicts with the new registry-based mapping  system when using DeclarativeMeta. While the attribute  remains something that can be set explicitly on a declarative base to be  consumed by the metaclass, once located it is placed under a private  class variable so it does not conflict with future subclasses that use  the same name for other purposes.
    References: #6054

engine

  • [engine] [bug] [regression]
    The Python namedtuple() has the behavior such that the names count and index will be served as tuple values if the named tuple includes those names; if they are absent, then their behavior as methods of collections.abc.Sequence is maintained. Therefore the Row and LegacyRow classes have been fixed so that they work in this same way, maintaining  the expected behavior for database rows that have columns named “index”  or “count”.
    References: #6074

mssql

  • [mssql] [bug] [regression]
    Fixed  regression where a new setinputsizes() API that’s available for pyodbc  was enabled, which is apparently incompatible with pyodbc’s  fast_executemany() mode in the absence of more accurate typing  information, which as of yet is not fully implemented or tested. The  pyodbc dialect and connector has been modified so that setinputsizes()  is not used at all unless the parameter use_setinputsizes is passed to the dialect, e.g. via create_engine(), at which point its behavior can be customized using the DialectEvents.do_setinputsizes() hook.
    See also
    Setinputsizes Support
    References: #6058

misc

  • [bug] [regression]
    Added back items and values to ColumnCollection class. The regression was introduced while adding support for duplicate columns in from clauses and selectable in ticket #4753.
    References: #6068


SqlAlchemy 2.0 中文文档(五十九)(7)https://developer.aliyun.com/article/1563153

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4月前
|
SQL 关系型数据库 MySQL
SqlAlchemy 2.0 中文文档(五十九)(2)
SqlAlchemy 2.0 中文文档(五十九)
31 0
|
4月前
|
SQL 关系型数据库 MySQL
SqlAlchemy 2.0 中文文档(五十九)(4)
SqlAlchemy 2.0 中文文档(五十九)
28 0
|
4月前
|
SQL 关系型数据库 PostgreSQL
SqlAlchemy 2.0 中文文档(五十九)(7)
SqlAlchemy 2.0 中文文档(五十九)
24 0
|
4月前
|
SQL 缓存 Oracle
SqlAlchemy 2.0 中文文档(五十九)(1)
SqlAlchemy 2.0 中文文档(五十九)
160 0
|
4月前
|
SQL 关系型数据库 MySQL
SqlAlchemy 2.0 中文文档(五十九)(3)
SqlAlchemy 2.0 中文文档(五十九)
34 0
|
4月前
|
SQL 关系型数据库 PostgreSQL
SqlAlchemy 2.0 中文文档(五十九)(5)
SqlAlchemy 2.0 中文文档(五十九)
31 0
|
4月前
|
SQL NoSQL 数据库
SqlAlchemy 2.0 中文文档(五十二)(5)
SqlAlchemy 2.0 中文文档(五十二)
29 0
|
4月前
|
SQL 测试技术 数据库
SqlAlchemy 2.0 中文文档(五十二)(1)
SqlAlchemy 2.0 中文文档(五十二)
26 0
|
4月前
|
SQL 数据库连接 Linux
SqlAlchemy 2.0 中文文档(五十二)(4)
SqlAlchemy 2.0 中文文档(五十二)
67 0
|
4月前
|
SQL NoSQL 数据库
SqlAlchemy 2.0 中文文档(五十二)(2)
SqlAlchemy 2.0 中文文档(五十二)
37 0