summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
Commit message (Collapse)AuthorAgeFilesLines
...
* | | reorg bulk persistence into a separate moduleMike Bayer2022-08-115-1097/+1162
|/ / | | | | | | | | | | | | | | | | | | | | | | This restores persistence.py to only functions that are used by unitofwork.py, and all the "bulk" stuff gets its own module bulk_persistence.py. Also fixes up the ORM context class hierarchy for bulk. This is all ahead of the ORM-insert changes coming in, so that the later review can be about logic and not about reorganization. Change-Id: I035896e9e77fcece866d246edf30097cccad0182
* | doc fixesMike Bayer2022-08-104-18/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fixed erroneous use of mapped_column() in m2m relationship Table * Fill in full imports for some relationship examples that had partial imports; examples that have no imports, leave empty for now * converted joined/single inh mappings to annotated style * We have a problem with @declared_attr in that the error message is wrong if the mapped_column() returned doesnt have a type, and/or mapped_column() with @declared_attr doesnt use the annotation * fix thing where sphinx with undoc-members global setting seems to no longer tolerate ":attribute:" entries in autodoc classes, which is fine we can document the annotations now * Fix mapper params in inheritance to be on Mapper * add missing changelog file for instances remove Change-Id: I9b70b25a320d8122fade68bc4d1f82f8b72b26f3
* | repair doc warningsMike Bayer2022-08-083-3/+3
| | | | | | | | | | Change-Id: I446105028539a34da90d6b8ae4812965cc398ee5 (cherry picked from commit c539ee35229b03d61f2a10e9f5ab613201341e19)
* | deep compare CTEs before considering them conflictingMike Bayer2022-08-051-4/+13
| | | | | | | | | | | | | | | | | | | | | | Fixed issue where referencing a CTE multiple times in conjunction with a polymorphic SELECT could result in multiple "clones" of the same CTE being constructed, which would then trigger these two CTEs as duplicates. To resolve, the two CTEs are deep-compared when this occurs to ensure that they are equivalent, then are treated as equivalent. Fixes: #8357 Change-Id: I1f634a9cf7a6c4256912aac1a00506aecea3b0e2
* | Merge "translate joined inheritance cols in UPDATE/DELETE" into mainmike bayer2022-08-057-21/+197
|\ \
| * | translate joined inheritance cols in UPDATE/DELETEMike Bayer2022-08-057-21/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue in ORM enabled UPDATE when the statement is created against a joined-inheritance subclass, updating only local table columns, where the "fetch" synchronization strategy would not render the correct RETURNING clause for databases that use RETURNING for fetch synchronization. Also adjusts the strategy used for RETURNING in UPDATE FROM and DELETE FROM statements. Also fixes MariaDB which does not support RETURNING with DELETE..USING. this was not caught in tests because "fetch" strategy wasn't tested. so also adjust the ORMDMLState classes to look for "extra froms" first before adding RETURNING, add new parameters to interfaces for "update_returning_multitable" and "delete_returning_multitable". A new execution option is_delete_using=True, described in the changelog message, is added to allow the ORM to know up front if a certain statement should have a SELECT up front for "fetch" strategy. Fixes: #8344 Change-Id: I3dcdb68e6e97ab0807a573c2fdb3d53c16d063ba
* | | credit @zeeeeeb for PG Multirange patchMike Bayer2022-08-051-279/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Also move some of the PG docs to the .rst page so we can link to sections. References: #7156 Change-Id: If57abc768d4768058ffa768f9bf72f83c1ee6c29
* | | Merge "implement PG ranges/multiranges agnostically" into mainmike bayer2022-08-058-27/+495
|\ \ \
| * | | implement PG ranges/multiranges agnosticallyMike Bayer2022-08-058-27/+495
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ranges now work using a new Range object, multiranges as lists of Range objects (this is what asyncpg does. not sure why psycopg has a "Multirange" type). psycopg, psycopg2, and asyncpg are currently supported. It's not clear how to make ranges work with pg8000, likely needs string conversion; this is straightforward with the new archicture and can be added later. Fixes: #8178 Change-Id: Iab8d8382873d5c14199adbe3f09fd0dc17e2b9f1
* | | | Merge "fixes: #7156 - Adds support for PostgreSQL MultiRange type" into mainmike bayer2022-08-053-0/+72
|\ \ \ \ | |/ / /
| * | | fixes: #7156 - Adds support for PostgreSQL MultiRange typezeeeeb2022-08-043-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds functionality for PostgreSQL MultiRange type, as discussed in Issue #7156. As far as I can tell, only psycopg provides a [Multirange adaptation](https://www.psycopg.org/psycopg3/docs/basic/pgtypes.html#multirange-adaptation). Psycopg2 only supports a [Range adaptation/data type](https://www.psycopg.org/psycopg3/docs/basic/pgtypes.html#multirange-adaptation). This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [x] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. Closes: #7816 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7816 Pull-request-sha: 7e9e0c858dcdb58d4fcca24964ef8d58d1842d41 Change-Id: I345e0f58f534ac37709a7a4627b6de8ddd8fa89e
* | | | Merge "include column.default, column.onupdate in eager_defaults" into mainmike bayer2022-08-053-33/+87
|\ \ \ \
| * | | | include column.default, column.onupdate in eager_defaultsMike Bayer2022-08-053-33/+87
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed bug in the behavior of the :paramref:`_orm.Mapper.eager_defaults` parameter such that client-side SQL default or onupdate expressions in the table definition alone will trigger a fetch operation using RETURNING or SELECT when the ORM emits an INSERT or UPDATE for the row. Previously, only server side defaults established as part of table DDL and/or server-side onupdate expressions would trigger this fetch, even though client-side SQL expressions would be included when the fetch was rendered. Fixes: #7438 Change-Id: Iba719298ba4a26d185edec97ba77d2d54585e5a4
* | | | Merge "Support kw_only and match_args in dataclass mapping" into mainmike bayer2022-08-054-40/+52
|\ \ \ \
| * | | | Support kw_only and match_args in dataclass mappingFederico Caselli2022-08-044-40/+52
| | |/ / | |/| | | | | | | | | | | | | | Fixes: #8346 Change-Id: I964629e3bd25221bf6df6ab31c59b3ce1983cd9a
* | | | Merge "deprecate Query.instances()" into mainmike bayer2022-08-041-0/+7
|\ \ \ \ | |/ / / |/| | |
| * | | deprecate Query.instances()Mike Bayer2022-08-041-0/+7
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | this method no longer does the thing that it was originally intended to do, which is to get ORM results from arbitrary result sets. Modern patterns should supersede the use of this construct. Change-Id: Ia1656c84d7c323f55e3a9594b950a40763d63d90 References: #8347
* | | Merge "Fix 'No transaction found' error on Synapse." into mainmike bayer2022-08-042-31/+77
|\ \ \ | |/ / |/| |
| * | Fix 'No transaction found' error on Synapse.Gord Thompson2022-08-022-31/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where the SQL Server dialect's query for the current isolation level would fail on Azure Synapse Analytics, due to the way in which this database handles transaction rollbacks after an error has occurred. The initial query has been modified to no longer rely upon catching an error when attempting to detect the appropriate system view. Additionally, to better support this database's very specific "rollback" behavior, implemented new parameter ``ignore_no_transaction_on_rollback`` indicating that a rollback should ignore Azure Synapse error 'No corresponding transaction found. (111214)', which is raised if no transaction is present in conflict with the Python DBAPI. Fixes: #8231 Closes: #8233 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8233 Pull-request-sha: c48bd44a9f53d00e5e94f1b8bf996711b6419562 Change-Id: I6407a03148f45cc9eba8fe1d31d4f59ebf9c7ef7
* | | Merge "ensure RETURNING renders in stringify w/ no server version" into mainmike bayer2022-08-043-2/+15
|\ \ \
| * | | ensure RETURNING renders in stringify w/ no server versionMike Bayer2022-08-033-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | just in my own testing, if I say insert().return_defaults() and stringify, I should see it, so make sure all the dialects default to "insert_returning" etc. , with downgrade on server version check. Change-Id: Id64e78fcb03c48b5dcb0feb21cb9cc495edd15e9
* | | | update quoted_name docMike Bayer2022-08-041-1/+2
|/ / / | | | | | | | | | | | | Fixes: #8339 Change-Id: If78bc9babfdc6a4dde4e65d72858ac7a402cbb4d
* | | Merge "SQLite reflection ignores schema internal names" into mainmike bayer2022-08-021-17/+77
|\ \ \
| * | | SQLite reflection ignores schema internal namesFederico Caselli2022-08-011-17/+77
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added new parameter to SQLite for reflection methods called ``sqlite_include_internal=True``; when omitted, local tables that start with the prefix ``sqlite_``, which per SQLite documentation are noted as "internal schema" tables such as the ``sqlite_sequence`` table generated to support "AUTOINCREMENT" columns, will not be included in reflection methods that return lists of local objects. This prevents issues for example when using Alembic autogenerate, which previously would consider these SQLite-generated tables as being remove from the model. Fixes: #8234 Change-Id: I36ee7a053e04b6c46c912aaa0d7e035a5b88a4f9
* | | Merge "implement tuple-slices from .c collections" into mainmike bayer2022-08-021-26/+60
|\ \ \
| * | | implement tuple-slices from .c collectionsMike Bayer2022-08-011-26/+60
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added new syntax to the ``.c`` collection on all :class:`.FromClause` objects allowing tuples of keys to be passed to ``__getitem__()``, along with support for ``select()`` handling of ``.c`` collections directly, allowing the syntax ``select(table.c['a', 'b', 'c'])`` to be possible. The sub-collection returned is itself a :class:`.ColumnCollection` which is also directly consumable by :func:`_sql.select` and similar now. Fixes: #8285 Change-Id: I2236662c477ffc50af079310589e213323c960d1
* | | fix up SAVEPOINT docsMike Bayer2022-08-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | these contained a factual error that the entire session is expired, which is no longer the case (I can't find exactly when this was changed). Additionally, added a PostgreSQL specific example w/ IntegrityError as this is the most common case for this. Tried to tighten up other language and make it as clear as possible. Change-Id: I39160e7443964db59d1d5a2e0616084767813eea
* | | repair psycopg2 (and psycopg) multiple hosts formatMike Bayer2022-08-013-17/+55
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue in psycopg2 dialect where the "multiple hosts" feature implemented for :ticket:`4392`, where multiple ``host:port`` pairs could be passed in the query string as ``?host=host1:port1&host=host2:port2&host=host3:port3`` was not implemented correctly, as it did not propagate the "port" parameter appropriately. Connections that didn't use a different "port" likely worked without issue, and connections that had "port" for some of the entries may have incorrectly passed on that hostname. The format is now corrected to pass hosts/ports appropriately. As part of this change, maintained support for another multihost style that worked unintentionally, which is comma-separated ``?host=h1,h2,h3&port=p1,p2,p3``. This format is more consistent with libpq's query-string format, whereas the previous format is inspired by a different aspect of libpq's URI format but is not quite the same thing. If the two styles are mixed together, an error is raised as this is ambiguous. Fixes: #4392 Change-Id: Ic9cc0b0e6e90725e158d9efe73e042853dd1263f
* | Remove `__cmp__` methods (#8313)Nikita Sobolev2022-07-313-7/+1
| |
* | Update to flake8 5.Federico Caselli2022-07-3113-42/+64
| | | | | | | | Change-Id: I5a241a70efba68bcea9819ddce6aebc25703e68d
* | Remove all `__nonzero__` methods (#8308)Nikita Sobolev2022-07-306-18/+0
| |
* | Merge "feat: add `drop constraint if exists` to compiler" into mainmike bayer2022-07-281-2/+3
|\ \
| * | feat: add `drop constraint if exists` to compilerMike Fiedler2022-07-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Description Add `DROP CONSTRAINT ... IF EXISTS` behavior to the compiler. Fixes https://github.com/sqlalchemy/sqlalchemy/issues/8141 ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [x] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #8161 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8161 Pull-request-sha: 43276e29fa864fc66900c5a3fa0bf84df5f14271 Change-Id: I18bae3cf013159b6fffde4413fb59ce19ff83c16
* | | Reflect expression-based indexes on PostgreSQLFederico Caselli2022-07-288-82/+201
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The PostgreSQL dialect now supports reflection of expression based indexes. The reflection is supported both when using :meth:`_engine.Inspector.get_indexes` and when reflecting a :class:`_schema.Table` using :paramref:`_schema.Table.autoload_with`. Thanks to immerrr and Aidan Kane for the help on this ticket. Fixes: #7442 Change-Id: I3e36d557235286c0f7f6d8276272ff9225058d48
* | | fix lambda styles for relationshipMike Bayer2022-07-251-1/+8
| | | | | | | | | | | | Change-Id: I810fafc4cbcf0ac9b1f0de764130c81c56367a16
* | | set up Literal for synchronize_sessionMike Bayer2022-07-232-2/+9
| | | | | | | | | | | | | | | Fixes: #8280 Change-Id: I59bc6cc0483375f79e17952188e0c2cde926502c
* | | Merge "Use FETCH FIRST N ROWS / OFFSET for Oracle LIMIT/OFFSET" into mainmike bayer2022-07-203-44/+106
|\ \ \
| * | | Use FETCH FIRST N ROWS / OFFSET for Oracle LIMIT/OFFSETMike Bayer2022-07-203-44/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Oracle will now use FETCH FIRST N ROWS / OFFSET syntax for limit/offset support by default for Oracle 12c and above. This syntax was already available when :meth:`_sql.Select.fetch` were used directly, it's now implied for :meth:`_sql.Select.limit` and :meth:`_sql.Select.offset` as well. I'm currently setting this up so that the new syntax renders in Oracle using POSTCOMPILE binds. I really have no indication if Oracle's SQL optimizer would be better with params here, so that it can cache the SQL plan, or if it expects hardcoded numbers for these. Since we had reports that the previous ROWNUM thing really needed hardcoded ints, let's guess for now that hardcoded ints would be preferable. it can be turned off with a single boolean if users report that they'd prefer real bound values. Fixes: #8221 Change-Id: I812ec24ffc947199866947b666d6ec6e6a690f22
* | | | add an extra load for non-new but unloadedMike Bayer2022-07-201-0/+6
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Made an improvement to the "deferred" / "load_only" set of strategy options where if a certain object is loaded from two different logical paths within one query, attributes that have been configured by at least one of the options to be populated will be populated in all cases, even if other load paths for that same object did not set this option. previously, it was based on randomness as to which "path" addressed the object first. Fixes: #8166 Change-Id: I923a1484721d3a04d490ef882bc9fa609c9cd077
* | | Merge "fixes for mypy 0.971" into mainmike bayer2022-07-196-33/+82
|\ \ \
| * | | fixes for mypy 0.971Mike Bayer2022-07-196-33/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | things that were passing with 0.961 need adjustment. it seems mypy has become very pedantic about the difference between importing from a module vs. accessing members of that module as instance variables, so adjust the preloaded typing block to be explicitly instance variables, since that's how the accessor works in any case. Change-Id: I746a3c9102530b7cf9b123aec7be6376657c1169
* | | | Merge "Ensure that a daclarative base is not used directly" into mainmike bayer2022-07-191-10/+24
|\ \ \ \
| * | | | Ensure that a daclarative base is not used directlyFederico Caselli2022-07-181-10/+24
| | | | | | | | | | | | | | | | | | | | | | | | | Fixes: #8248 Change-Id: I4f4c690dd8659eaf74e9c757d681e9edc7d33eee
* | | | | check for TypeDecorator when handling getitemMike Bayer2022-07-192-2/+27
| |/ / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where :class:`.TypeDecorator` would not correctly proxy the ``__getitem__()`` operator when decorating the :class:`.ARRAY` datatype, without explicit workarounds. Fixes: #7249 Change-Id: I3273572b4757e41fb5952639cb867314227d368a
* | | | Merge "add shield() in aexit" into mainmike bayer2022-07-182-8/+16
|\ \ \ \ | |/ / / |/| | |
| * | | add shield() in aexitFederico Caselli2022-07-182-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added ``asyncio.shield()`` to the connection and session release process specifically within the ``__aexit__()`` context manager exit, when using :class:`.AsyncConnection` or :class:`.AsyncSession` as a context manager that releases the object when the context manager is complete. This appears to help with task cancellation when using alternate concurrency libraries such as ``anyio``, ``uvloop`` that otherwise don't provide an async context for the connection pool to release the connection properly during task cancellation. Fixes: #8145 Change-Id: I0b1ea9c3a22a18619341cbb8591225fcd339042c
* | | | Merge "implement executemany RETURNING for Oracle" into mainmike bayer2022-07-181-13/+29
|\ \ \ \
| * | | | implement executemany RETURNING for OracleMike Bayer2022-07-181-13/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | this works straight out of the box as we can expand upon what we did for #6245 to also receive for multiple statements. Oracle "fast ORM insert" then is basically done. Fixes: #6245 Change-Id: I32902d199d473bc38cd03d14fec7482e1b37cd5b
* | | | | Merge "add contextmanager typing, open run_sync typing" into mainmike bayer2022-07-182-14/+9
|\ \ \ \ \ | |/ / / / |/| | | |
| * | | | add contextmanager typing, open run_sync typingMike Bayer2022-07-182-14/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | was missing AsyncConnection type for the async context manager. fixing that revealed that _SyncConnectionCallable and _SyncSessionCallable protocols are infeasible because the given callable can have a lot of different signatures that are compatible. Change-Id: I559aa3dd88a902d0e7681c52223bb4bc0890adc1