github sqlalchemy/sqlalchemy rel_2_0_22
2.0.22

latest releases: rel_2_0_35, rel_1_4_54, rel_2_0_34...
11 months ago

2.0.22

Released: October 12, 2023

orm

  • [orm] [usecase] Added method _orm.Session.get_one() that behaves like
    _orm.Session.get() but raises an exception instead of returning
    None if no instance was found with the provided primary key.
    Pull request courtesy of Carlos Sousa.

    References: #10202

  • [orm] [usecase] Added an option to permanently close sessions.
    Set to False the new parameter _orm.Session.close_resets_only
    will prevent a _orm.Session from performing any other
    operation after _orm.Session.close() has been called.

    Added new method _orm.Session.reset() that will reset a _orm.Session
    to its initial state. This is an alias of _orm.Session.close(),
    unless _orm.Session.close_resets_only is set to False.

    References: #7787

  • [orm] [bug] Fixed a wide range of _orm.mapped_column() parameters that were not
    being transferred when using the _orm.mapped_column() object inside
    of a pep-593 Annotated object, including
    _orm.mapped_column.sort_order,
    _orm.mapped_column.deferred,
    _orm.mapped_column.autoincrement,
    _orm.mapped_column.system, _orm.mapped_column.info
    etc.

    Additionally, it remains not supported to have dataclass arguments, such as
    _orm.mapped_column.kw_only,
    _orm.mapped_column.default_factory etc. indicated within the
    _orm.mapped_column() received by Annotated, as this is not
    supported with pep-681 Dataclass Transforms. A warning is now emitted when
    these parameters are used within Annotated in this way (and they
    continue to be ignored).

    References: #10046, #10369

  • [orm] [bug] Fixed issue where calling _engine.Result.unique() with a new-style
    select() query in the ORM, where one or more columns yields values
    that are of "unknown hashability", typically when using JSON functions like
    func.json_build_object() without providing a type, would fail
    internally when the returned values were not actually hashable. The
    behavior is repaired to test the objects as they are received for
    hashability in this case, raising an informative error message if not. Note
    that for values of "known unhashability", such as when the
    _types.JSON or _types.ARRAY types are used directly, an
    informative error message was already raised.

    The "hashabiltiy testing" fix here is applied to legacy Query as
    well, however in the legacy case, _engine.Result.unique() is used for
    nearly all queries, so no new warning is emitted here; the legacy behavior
    of falling back to using id() in this case is maintained, with the
    improvement that an unknown type that turns out to be hashable will now be
    uniqufied, whereas previously it would not.

    References: #10459

  • [orm] [bug] Fixed regression in recently revised "insertmanyvalues" feature (likely
    issue #9618) where the ORM would inadvertently attempt to
    interpret a non-RETURNING result as one with RETURNING, in the case where
    the implicit_returning=False parameter were applied to the mapped
    Table, indicating that "insertmanyvalues" cannot be used if the
    primary key values are not provided.

    References: #10453

  • [orm] [bug] Fixed bug where ORM _orm.with_loader_criteria() would not apply
    itself to a _sql.Select.join() where the ON clause were given as a
    plain SQL comparison, rather than as a relationship target or similar.

    References: #10365

  • [orm] [bug] Fixed issue where Mapped symbols like WriteOnlyMapped
    and DynamicMapped could not be correctly resolved when referenced
    as an element of a sub-module in the given annotation, assuming
    string-based or "future annotations" style annotations.

    References: #10412

  • [orm] [bug] Fixed issue with __allow_unmapped__ declarative option
    where types that were declared using collection types such as
    list[SomeClass] vs. the typing construct List[SomeClass]
    would fail to be recognized correctly. Pull request courtesy
    Pascal Corpet.

    References: #10385

engine

  • [engine] [bug] Fixed issue within some dialects where the dialect could incorrectly return
    an empty result set for an INSERT statement that does not actually return
    rows at all, due to artfacts from pre- or post-fetching the primary key of
    the row or rows still being present. Affected dialects included asyncpg,
    all mssql dialects.

  • [engine] [bug] Fixed issue where under some garbage collection / exception scenarios the
    connection pool's cleanup routine would raise an error due to an unexpected
    set of state, which can be reproduced under specific conditions.

    References: #10414

sql

  • [sql] [bug] Fixed issue where referring to a FROM entry in the SET clause of an UPDATE
    statement would not include it in the FROM clause of the UPDATE statement,
    if that entry were nowhere else in the statement; this occurs currently for
    CTEs that were added using Update.add_cte() to provide the desired
    CTE at the top of the statement.

    References: #10408

  • [sql] [bug] Fixed 2.0 regression where the DDL construct would no longer
    __repr__() due to the removed on attribute not being accommodated.
    Pull request courtesy Iuri de Silvio.

    References: #10443

typing

  • [typing] [bug] Fixed typing issue where the argument list passed to Values was
    too-restrictively tied to List rather than Sequence. Pull request
    courtesy Iuri de Silvio.

    References: #10451

  • [typing] [bug] Updates to the codebase to support Mypy 1.6.0.

asyncio

  • [asyncio] [bug] Fixed the _asyncio.AsyncSession.get.execution_options parameter
    which was not being propagated to the underlying _orm.Session and
    was instead being ignored.

mariadb

  • [mariadb] [bug] Modified the mariadb-connector driver to pre-load the cursor.rowcount
    value for all queries, to suit tools such as Pandas that hardcode to
    calling Result.rowcount in this way. SQLAlchemy normally pre-loads
    cursor.rowcount only for UPDATE/DELETE statements and otherwise passes
    through to the DBAPI where it can return -1 if no value is available.
    However, mariadb-connector does not support invoking cursor.rowcount
    after the cursor itself is closed, raising an error instead. Generic test
    support has been added to ensure all backends support the allowing
    Result.rowcount to succceed (that is, returning an integer
    value with -1 for "not available") after the result is closed.

    References: #10396

  • [mariadb] [bug] Additional fixes for the mariadb-connector dialect to support UUID data
    values in the result in INSERT..RETURNING statements.

mssql

  • [mssql] [bug] Fixed bug where the rule that prevents ORDER BY from emitting within
    subqueries on SQL Server was not being disabled in the case where the
    select.fetch() method were used to limit rows in conjunction with
    WITH TIES or PERCENT, preventing valid subqueries with TOP / ORDER BY from
    being used.

    References: #10458

Don't miss a new sqlalchemy release

NewReleases is sending notifications on new releases.