summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | use read-only Mapping for values dictionary typeMike Bayer2023-02-262-1/+6
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | Improved typing for the mapping passed to :meth:`.UpdateBase.values` to be more open-ended about collection type, by indicating read-only ``Mapping`` instead of writeable ``Dict``, the latter of which would error out under typing tools on too limited of a key type. Fixes: #9376 Change-Id: Ib7fdbba05ca7e1082409e1b5616e6a010262f032
* | | Merge "locate automap base in hierarchy directly" into mainmike bayer2023-02-271-5/+15
|\ \ \
| * | | locate automap base in hierarchy directlyMike Bayer2023-02-241-5/+15
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue in automap where calling ``.prepare()`` from one of the mapped classes would not use the correct base class when automap detected new tables, instead using the given class, leading to mappers trying to configure inheritance. While one should normally call ``.prepare()`` from the base in any case, it shouldn't misbehave that badly when called from a subclass. Fixes: #9367 Change-Id: I705d4d939d45af52bc58a74e65994205ab791634
* | | ExcludeConstraint literal_compileFederico Caselli2023-02-222-9/+9
|/ / | | | | | | | | | | | | | | ExcludeConstraint correctly uses literal compile when compiling expression ddl. Fixes: #9349 Change-Id: I11a994ac46556a972afc696a2baad7ddbdd3de97
* | add notes to all mapper flush events that these are only for flushMike Bayer2023-02-211-0/+36
|/ | | | | Fixes: #9339 Change-Id: I44542166417776733245e2ba39cd5de89b6d748b
* Fix the docstring of AppenerQuery.append() (#9336)Grey Li2023-02-201-2/+2
|
* Fix a syntax error in `AsyncConnection.stream_scalars()` example. (#9334)Vytautas Liuolia2023-02-191-1/+1
|
* consider column.name directly when evaluating use_existing_columnMike Bayer2023-02-181-1/+2
| | | | | | | | | | | Fixed issue where new :paramref:`_orm.mapped_column.use_existing_column` feature would not work if the two same-named columns were mapped under attribute names that were differently-named from the explicit name given to the column itself. The attribute names can now be differently named when using this parameter. Fixes: #9332 Change-Id: I43716b8ca2b089e54a2b078db28b6c4770468bdd
* more editsMike Bayer2023-02-171-2/+2
| | | | | | | I can only see issues in the docs when they're live on the site, sorry Change-Id: I948b7c8e37657ca85d02843211cbfdb03aa5da75
* typo, captionsMike Bayer2023-02-171-1/+5
| | | | Change-Id: I547e66b60f5a7b2901a76ebc59469bce018e05ff
* Version 2.0.5 placeholderMike Bayer2023-02-171-1/+1
|
* rework hybrid docs furtherMike Bayer2023-02-171-88/+126
| | | | | | | we have a very complicated story to tell and we need to keep it within "reference doc" mode as much as we can Change-Id: I873b7d95aea7b5a1d04de0c78a4e88651c908b35
* Allow custom sorting of column in the ORM.Federico Caselli2023-02-167-20/+51
| | | | | | | | | | | | | | | To accommodate a change in column ordering used by ORM Declarative in SQLAlchemy 2.0, a new parameter :paramref:`_orm.mapped_column.sort_order` has been added that can be used to control the order of the columns defined in the table by the ORM, for common use cases such as mixins with primary key columns that should appear first in tables. The change notes at :ref:`change_9297` illustrate the default change in ordering behavior (which is part of all SQLAlchemy 2.0 releases) as well as use of the :paramref:`_orm.mapped_column.sort_order` to control column ordering when using mixins and multiple classes (new in 2.0.4). Fixes: #9297 Change-Id: Ic7163d64efdc0eccb53d6ae0dd89ec83427fb675
* Merge "modernize hybrids and apply typing" into mainmike bayer2023-02-173-180/+423
|\
| * modernize hybrids and apply typingMike Bayer2023-02-163-180/+423
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improved the typing support for the :ref:`hybrids_toplevel` extension, updated all documentation to use ORM Annotated Declarative mappings, and added a new modifier called :attr:`.hybrid_property.inplace`. This modifier provides a way to alter the state of a :class:`.hybrid_property` **in place**, which is essentially what very early versions of hybrids did, before SQLAlchemy version 1.2.0 :ticket:`3912` changed this to remove in-place mutation. This in-place mutation is now restored on an **opt-in** basis to allow a single hybrid to have multiple methods set up, without the need to name all the methods the same and without the need to carefully "chain" differently-named methods in order to maintain the composition. Typing tools such as Mypy and Pyright do not allow same-named methods on a class, so with this change a succinct method of setting up hybrids with typing support is restored. Change-Id: Iea88025f023428f9f006846d09fbb4be391f5ebb References: #9321
* | Merge "Fix coercion issue for tuple bindparams" into mainmike bayer2023-02-163-4/+30
|\ \ | |/ |/|
| * Fix coercion issue for tuple bindparamsmike bayer2023-02-153-4/+30
| | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where element types of a tuple value would be hardcoded to take on the types from a compared-to tuple, when the comparison were using the :meth:`.ColumnOperators.in_` operator. This was inconsistent with the usual way that types are determined for a binary expression, which is that the actual element type on the right side is considered first before applying the left-hand-side type. Fixes: #9313 Change-Id: Ia8874c09682a6512fcf4084cf14481024959c461
* | Merge "rename EvaluatorCompiler to _EvaluatorCompiler" into mainmike bayer2023-02-162-3/+29
|\ \
| * | rename EvaluatorCompiler to _EvaluatorCompilerMike Bayer2023-02-162-3/+29
| |/ | | | | | | | | | | | | | | This is a private class, mark as such as some users may have used this class directly in end-user code. Change-Id: I2657eff1f9f11b59c0483922ac67d6420a082906 References: #9299
* | Merge "add dataclasses callable and apply annotations more strictly" into mainmike bayer2023-02-162-13/+82
|\ \
| * | add dataclasses callable and apply annotations more strictlyMike Bayer2023-02-162-13/+82
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added new parameter ``dataclasses_callable`` to both the :class:`_orm.MappedAsDataclass` class as well as the :meth:`_orm.registry.mapped_as_dataclass` method which allows an alternative callable to Python ``dataclasses.dataclass`` to be used in order to produce dataclasses. The use case here is to drop in Pydantic's dataclass function instead. Adjustments have been made to the mixin support added for :ticket:`9179` in version 2.0.1 so that the ``__annotations__`` collection of the mixin is rewritten to not include the :class:`_orm.Mapped` container, in the same way as occurs with mapped classes, so that the Pydantic dataclasses constructor is not exposed to unknown types. Fixes: #9266 Change-Id: Ia0fab6f20b93a5cb853799dcf1b70a0386837c14
* | immediateload lazy relationships named in refresh.attribute_namesMike Bayer2023-02-165-28/+78
|/ | | | | | | | | | | | | | | | | | The :meth:`_orm.Session.refresh` method will now immediately load a relationship-bound attribute that is explicitly named within the :paramref:`_orm.Session.refresh.attribute_names` collection even if it is currently linked to the "select" loader, which normally is a "lazy" loader that does not fire off during a refresh. The "lazy loader" strategy will now detect that the operation is specifically a user-initiated :meth:`_orm.Session.refresh` operation which named this attribute explicitly, and will then call upon the "immediateload" strategy to actually emit SQL to load the attribute. This should be helpful in particular for some asyncio situations where the loading of an unloaded lazy-loaded attribute must be forced, without using the actual lazy-loading attribute pattern not supported in asyncio. Fixes: #9298 Change-Id: I9b50f339bdf06cdb2ec98f8e5efca2b690895dd7
* prevent float tests from running on asyncmyMike Bayer2023-02-152-4/+16
| | | | | | | | asyncmy 0.2.7 has had a loss in float precision for even very low numbers of significant digits. Change-Id: Iec6d2650943eeaa8e854f21990f6565d73331f8c References: https://github.com/long2ice/asyncmy/issues/56
* Merge "Improve ``oracledb`` thick mode flag." into mainmike bayer2023-02-151-1/+3
|\
| * Improve ``oracledb`` thick mode flag.Federico Caselli2023-02-141-1/+3
| | | | | | | | | | | | | | | | Adjusted ``oracledb`` thick mode flag to make ``thick_mode=False`` not enable thick mode. Previously only ``None`` was accepted as off value. Fixes: #9295 Change-Id: I1a8397c19d065dfc2dda597e719922fc8d31acb1
* | Merge "Add ``Table.autoincrement_column``" into mainmike bayer2023-02-151-2/+24
|\ \
| * | Add ``Table.autoincrement_column``Federico Caselli2023-02-141-2/+24
| | | | | | | | | | | | | | | | | | | | | | | | Added public property :attr:`_sql.Table.autoincrement_column` that returns the column identified as autoincrementing in the column. Fixes: #9277 Change-Id: If60d6f92e0df94f57d00ff6d89d285c61b02f5a4
* | | fix typo "Annotation" -> "Annotated" and use typing_extensionsMike Bayer2023-02-141-2/+2
| |/ |/| | | | | | | Fixes: #9305 Change-Id: I9f0ab24f609f6f557b5780209a85f0abe82b363e
* | completely lift-and-copy and_ / or_ documentationMike Bayer2023-02-131-0/+108
| | | | | | | | | | | | | | | | Sphinx refuses to write the correct docstring for these without placing a completely literal string with no interpolation of any kind. Current site has blank for these. Change-Id: Ie19a0b89d05b45509708585e6efca1a35f30adb5
* | Fix docs for `case` expression to match new syntax (#9279)Abdulhaq Emhemmed2023-02-103-7/+7
|/ | | | | | | | | * Fix docs for `case` expression to match new syntax Previously (before v1.4), the `whens` arg (when `value` is *not* used) used to be a list of conditions (a 2 item-tuple of condition + value). From v1.4, these are passed as positional args and the old syntax is not supported anymore. * Fix long lines
* generalize adapt_on_names to expect non-named elementsMike Bayer2023-02-103-8/+20
| | | | | | | | | | | | | | | | | | | | The fix in #9217 opened up adapt_on_names to more kinds of expressions than it was prepared for; adjust that logic and also refine in the ORM where we are using it, as we dont need it (yet) for the DML RETURNING use case. Fixed regression introduced in version 2.0.2 due to :ticket:`9217` where using DML RETURNING statements, as well as :meth:`_sql.Select.from_statement` constructs as was "fixed" in :ticket:`9217`, in conjunction with ORM mapped classes that used expressions such as with :func:`_orm.column_property`, would lead to an internal error within Core where it would attempt to match the expression by name. The fix repairs the Core issue, and also adjusts the fix in :ticket:`9217` to not take effect for the DML RETURNING use case, where it adds unnecessary overhead. Fixes: #9273 Change-Id: Ie0344efb12ff7df48f21e71e62dc598c76a6a0de
* Version 2.0.4 placeholderMike Bayer2023-02-091-1/+1
|
* apply self_group to all elements of multi-expressionMike Bayer2023-02-091-8/+9
| | | | | | | | | | | Fixed critical regression in SQL expression formulation in the 2.0 series due to :ticket:`7744` which improved support for SQL expressions that contained many elements against the same operator repeatedly; parenthesis grouping would be lost with expression elements beyond the first two elements. Fixes: #9271 Change-Id: Ib6ed5b71efe0f6816dab75bda622297fc89e3b49
* typing: fix hybrid property setter (#9269)Mehdi ABAAKOUK2023-02-081-1/+1
| | | Fixes #9268
* Remove `typing.Self` workaroundYurii Karabas2023-02-0827-705/+375
| | | | | | | | | | | | Remove ``typing.Self`` workaround, now using :pep:`673` for most methods that return ``Self``. Pull request courtesy Yurii Karabas. Fixes: #9254 Closes: #9255 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9255 Pull-request-sha: 2947df8ada79f5c3afe9c838e65993302199c2f7 Change-Id: Ic32015ad52e95a61f3913d43ea436aa9402804df
* Version 2.0.3 placeholderMike Bayer2023-02-061-1/+1
|
* Merge "do not return asyncio connections to the pool under gc" into mainmike bayer2023-02-061-25/+40
|\
| * do not return asyncio connections to the pool under gcMike Bayer2023-02-061-25/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Repaired a regression caused by the fix for :ticket:`8419` which caused asyncpg connections to be reset (i.e. transaction ``rollback()`` called) and returned to the pool normally in the case that the connection were not explicitly returned to the connection pool and was instead being intercepted by Python garbage collection, which would fail if the garbage collection operation were being called outside of the asyncio event loop, leading to a large amount of stack trace activity dumped into logging and standard output. The correct behavior is restored, which is that all asyncio connections that are garbage collected due to not being explicitly returned to the connection pool are detached from the pool and discarded, along with a warning, rather than being returned the pool, as they cannot be reliably reset. In the case of asyncpg connections, the asyncpg-specific ``terminate()`` method will be used to end the connection more gracefully within this process as opposed to just dropping it. This change includes a small behavioral change that is hoped to be useful for debugging asyncio applications, where the warning that's emitted in the case of asyncio connections being unexpectedly garbage collected has been made slightly more aggressive by moving it outside of a ``try/except`` block and into a ``finally:`` block, where it will emit unconditionally regardless of whether the detach/termination operation succeeded or not. It will also have the effect that applications or test suites which promote Python warnings to exceptions will see this as a full exception raise, whereas previously it was not possible for this warning to actually propagate as an exception. Applications and test suites which need to tolerate this warning in the interim should adjust the Python warnings filter to allow these warnings to not raise. The behavior for traditional sync connections remains unchanged, that garbage collected connections continue to be returned to the pool normally without emitting a warning. This will likely be changed in a future major release to at least emit a similar warning as is emitted for asyncio drivers, as it is a usage error for pooled connections to be intercepted by garbage collection without being properly returned to the pool. Fixes: #9237 Change-Id: Ib35cfb2e628f2eb2da6d2b65674702556f55603a
* | Merge "add error code 1049 for mysql has_table" into mainFederico Caselli2023-02-063-1/+29
|\ \
| * | add error code 1049 for mysql has_tableMike Bayer2023-02-063-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed regression caused by issue :ticket:`9058` which adjusted the MySQL dialect's ``has_table()`` to again use "DESCRIBE", where the specific error code raised by MySQL version 8 when using a non-existent schema name was unexpected and failed to be interpreted as a boolean result. Fixed the SQLite dialect's ``has_table()`` function to correctly report False for queries that include a non-None schema name for a schema that doesn't exist; previously, a database error was raised. Fixes: #9251 Change-Id: I5ef9cf0887865c3c521d88bca0ba18954a108241
* | | Merge "Dedicated bitwise operators" into mainmike bayer2023-02-068-0/+180
|\ \ \
| * | | Dedicated bitwise operatorsjazzthief2023-02-068-0/+180
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a full suite of new SQL bitwise operators, for performing database-side bitwise expressions on appropriate data values such as integers, bit-strings, and similar. Pull request courtesy Yegor Statkevich. Fixes: #8780 Closes: #9204 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9204 Pull-request-sha: a4541772a6a784f9161ad78ef84d2ea7a62fa8de Change-Id: I4c70e80f9548dcc1b4e3dccd71bd59d51d3ed46e
* | | | Merge "use mysql 8 syntax for ON DUPLICATE KEY UPDATE" into mainmike bayer2023-02-061-7/+35
|\ \ \ \ | |_|/ / |/| | |
| * | | use mysql 8 syntax for ON DUPLICATE KEY UPDATECaspar Wylie2023-02-061-7/+35
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added support for MySQL 8's new ``AS <name> ON DUPLICATE KEY`` syntax when using :meth:`_mysql.Insert.on_duplicate_key_update`, which is required for newer versions of MySQL 8 as the previous syntax using ``VALUES()`` now emits a deprecation warning with those versions. Server version detection is employed to determine if traditional MariaDB / MySQL < 8 ``VALUES()`` syntax should be used, vs. the newer MySQL 8 required syntax. Pull request courtesy Caspar Wylie. Fixes: #8626 Closes: #9210 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9210 Pull-request-sha: 1c8dfbf0b4c439d9ca2c194524c47eb7239ee3c5 Change-Id: I42c463837af06bc15b60c534159804193df07f02
* | | Merge "port history meta to 2.0" into mainmike bayer2023-02-062-20/+71
|\ \ \
| * | | port history meta to 2.0Mike Bayer2023-02-062-20/+71
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | first change: Reworked the :ref:`examples_versioned_history` to work with version 2.0, while at the same time improving the overall working of this example to use newer APIs, including a newly added hook :meth:`_orm.MapperEvents.after_mapper_constructed`. second change: Added new event hook :meth:`_orm.MapperEvents.after_mapper_constructed`, which supplies an event hook to take place right as the :class:`_orm.Mapper` object has been fully constructed, but before the :meth:`_orm.registry.configure` call has been called. This allows code that can create additional mappings and table structures based on the initial configuration of a :class:`_orm.Mapper`, which also integrates within Declarative configuration. Previously, when using Declarative, where the :class:`_orm.Mapper` object is created within the class creation process, there was no documented means of running code at this point. The change is to immediately benefit custom mapping schemes such as that of the :ref:`examples_versioned_history` example, which generate additional mappers and tables in response to the creation of mapped classes. third change: The infrequently used :attr:`_orm.Mapper.iterate_properties` attribute and :meth:`_orm.Mapper.get_property` method, which are primarily used internally, no longer implicitly invoke the :meth:`_orm.registry.configure` process. Public access to these methods is extremely rare and the only benefit to having :meth:`_orm.registry.configure` would have been allowing "backref" properties be present in these collections. In order to support the new :meth:`_orm.MapperEvents.after_mapper_constructed` event, iteration and access to the internal :class:`_orm.MapperProperty` objects is now possible without triggering an implicit configure of the mapper itself. The more-public facing route to iteration of all mapper attributes, the :attr:`_orm.Mapper.attrs` collection and similar, will still implicitly invoke the :meth:`_orm.registry.configure` step thus making backref attributes available. In all cases, the :meth:`_orm.registry.configure` is always available to be called directly. fourth change: Fixed obscure ORM inheritance issue caused by :ticket:`8705` where some scenarios of inheriting mappers that indicated groups of columns from the local table and the inheriting table together under a :func:`_orm.column_property` would nonetheless warn that properties of the same name were being combined implicitly. Fixes: #9220 Fixes: #9232 Change-Id: Id335b8e8071c8ea509c057c389df9dcd2059437d
* | | check for superclasses of user defined initMike Bayer2023-02-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed regression caused by the fix for :ticket:`9171`, which itself was fixing a regression, involving the mechanics of ``__init__()`` on classes that extend from :class:`_orm.DeclarativeBase`. The change made it such that ``__init__()`` was applied to the user-defined base if there were no ``__init__()`` method directly on the class. This has been adjusted so that ``__init__()`` is applied only if no other class in the hierarchy of the user-defined base has an ``__init__()`` method. This again allows user-defined base classes based on :class:`_orm.DeclarativeBase` to include mixins that themselves include a custom ``__init__()`` method. Fixes: #9249 Change-Id: I78f32590ce9ffe245eccb4bd5bd7c884d4e015d5
* | | Merge "coerce elements in mapper.primary_key, process in __mapper_args__" ↵mike bayer2023-02-052-5/+56
|\ \ \ | | | | | | | | | | | | into main
| * | | coerce elements in mapper.primary_key, process in __mapper_args__Mike Bayer2023-02-052-6/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Repaired ORM Declarative mappings to allow for the :paramref:`_orm.Mapper.primary_key` parameter to be specified within ``__mapper_args__`` when using :func:`_orm.mapped_column`. Despite this usage being directly in the 2.0 documentation, the :class:`_orm.Mapper` was not accepting the :func:`_orm.mapped_column` construct in this context. Ths feature was already working for the :paramref:`_orm.Mapper.version_id_col` and :paramref:`_orm.Mapper.polymorphic_on` parameters. As part of this change, the ``__mapper_args__`` attribute may be specified without using :func:`_orm.declared_attr` on a non-mapped mixin class, including a ``"primary_key"`` entry that refers to :class:`_schema.Column` or :func:`_orm.mapped_column` objects locally present on the mixin; Declarative will also translate these columns into the correct ones for a particular mapped class. This again was working already for the :paramref:`_orm.Mapper.version_id_col` and :paramref:`_orm.Mapper.polymorphic_on` parameters. Additionally, elements within ``"primary_key"`` may be indicated as string names of existing mapped properties. Fixes: #9240 Change-Id: Ie2000273289fa23e0af21ef9c6feb3962a8b848c
* | | | Merge "Guard against wrong dataclass mapping" into mainFederico Caselli2023-02-051-0/+11
|\ \ \ \