summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
Commit message (Collapse)AuthorAgeFilesLines
...
| * | warn for no polymorphic identity w/ poly hierarchyMike Bayer2022-10-111-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A warning is emitted when attempting to configure a mapped class within an inheritance hierarchy where the mapper is not given any polymorphic identity, however there is a polymorphic discriminator column assigned. Such classes should be abstract if they never intend to load directly. Fixes: #7545 Change-Id: I94f04e59736c73e3f39d883a75d763e3f06ecc3d
* | | Merge "enable check same thread for aiosqlite" into mainmike bayer2022-10-111-13/+18
|\ \ \ | |/ / | | / | |/ |/|
| * enable check same thread for aiosqliteMike Bayer2022-10-111-13/+18
| | | | | | | | | | | | | | | | | | | | to do this we have to invent our own isolation level setter based on their current internals. however now we can ensure thread-safe access. we are trying to resolve an issue where test suite on CI seems to fail around the same time each time. Change-Id: I79c8fc04b9afef0876fb446ad40a7621a772cd34
* | Merge "rename MappedCollection and related" into mainmike bayer2022-10-113-32/+92
|\ \ | |/ |/|
| * rename MappedCollection and relatedMike Bayer2022-10-113-32/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For consistency with the prominent ORM concept :class:`_orm.Mapped`, the names of the dictionary-oriented collections, :func:`_orm.attribute_mapped_collection`, :func:`_orm.column_mapped_collection`, and :class:`_orm.MappedCollection`, are changed to :func:`_orm.attribute_keyed_dict`, :func:`_orm.column_keyed_dict` and :class:`_orm.KeyFuncDict`, using the phrase "dict" to minimize any confusion against the term "mapped". The old names will remain indefinitely with no schedule for removal. Docs here are also updated for typing as we can type these collections as ``Mapped[dict[str, cls]]``, don't need KeyFuncDict / MappedCollection for these Fixes: #8608 Change-Id: Ib5cf63e0aef1c389e023a75e454bb21f9d779b54
* | Merge "doc edits" into mainmike bayer2022-10-112-1/+6
|\ \
| * | doc editsMike Bayer2022-10-102-1/+6
| |/ | | | | | | | | | | | | | | | | this is addressing comments still remaining on I9929daab7797be9515f71c888b28af1209e789ff removes "asyncio" wording discussed in #7659 Change-Id: I1bab2a6fde330b83ef34602956c2988ee6331b21
* | dont mutate bind_arguments incoming dictionaryMike Bayer2022-10-072-1/+2
|/ | | | | | | | | | | | | | | The :paramref:`_orm.Session.execute.bind_arguments` dictionary is no longer mutated when passed to :meth:`_orm.Session.execute` and similar; instead, it's copied to an internal dictionary for state changes. Among other things, this fixes and issue where the "clause" passed to the :meth:`_orm.Session.get_bind` method would be incorrectly referring to the :class:`_sql.Select` construct used for the "fetch" synchronization strategy, when the actual query being emitted was a :class:`_dml.Delete` or :class:`_dml.Update`. This would interfere with recipes for "routing sessions". Fixes: #8614 Change-Id: I8d237449485c9bbf41db2b29a34b6136aa43b7bc
* implement write-only colletions, typing for dynamicMike Bayer2022-10-0619-568/+994
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For 2.0, we provide a truly "larger than memory collection" implementation, a write-only collection that will never under any circumstances implicitly load the entire collection, even during flush. This is essentially a much more "strict" version of the "dynamic" loader, which in fact has a lot of scenarios that it loads the full backing collection into memory, mostly defeating its purpose. Typing constructs are added that support both the new feature WriteOnlyMapping as well as the legacy feature DynamicMapping. These have been integrated with "annotion based mapping" so that relationship() uses these annotations to configure the loader strategy as well. additional changes: * the docs triggered a conflict in hybrid's "transformers" section, this section is hard-coded to Query using a pattern that doesnt seem to have any use and isn't part of the current select() interface, so just removed this section * As the docs for WriteOnlyMapping are very long, collections.rst is broken up into two pages now. Fixes: #6229 Fixes: #7123 Change-Id: I6929f3da6e441cad92285e7309030a9bac4e429d
* reorganize Mapped[] super outside of MapperPropertyMike Bayer2022-10-0523-136/+297
| | | | | | | | | | | | | | | | | | | | | | | | | | We made all the MapperProperty classes a subclass of Mapped[] to allow declarative mappings to name Mapped[] on the left side. this was cheating a bit because MapperProperty is not actually a descriptor, and the mapping process replaces the object with InstrumentedAttribute at mapping time, which is the actual Mapped[] descriptor. But now in I6929f3da6e441cad92285e7309030a9bac4e429d we are considering making the "cheating" a little more extensive by putting DynamicMapped / WriteOnlyMapped in Relationship's hierarchy, which need a flat out "type: ignore" to work. Instead of pushing more cheats into the core classes, move out the "Declarative"-facing versions of these classes to be typing only: Relationship, Composite, Synonym, and MappedSQLExpression added for ColumnProperty. Keep the internals expressed on the old names, RelationshipProperty, CompositeProperty, SynonymProperty, ColumnProprerty, which will remain "pure" with fully correct typing. then have the typing only endpoints be where the "cheating" and "type: ignores" have to happen, so that these are more or less slightly better forms of "Any". Change-Id: Ied7cc11196c9204da6851f49593d1b1fd2ef8ad8
* Merge "adjust MySQL view reflection for non-standard MySQL variants" into mainmike bayer2022-10-052-1/+6
|\
| * adjust MySQL view reflection for non-standard MySQL variantsJohn Bodley2022-10-032-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adjusted the regular expression used to match "CREATE VIEW" when testing for views to work more flexibly, no longer requiring the special keyword "ALGORITHM" in the middle, which was intended to be optional but was not working correctly. The change allows view reflection to work more completely on MySQL-compatible variants such as StarRocks. Pull request courtesy John Bodley. Fixes: #8588 Closes: #8589 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8589 Pull-request-sha: d85b2c5b51e45cec543c9ae9d62d6d659b063354 Change-Id: I173137f0bf68639cad0d5c329055475b40ddb5e4
* | Make if_exists and if_not_exists flags on ddl statements match compilerJesse Bakker2022-10-042-42/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added ``if_exists`` and ``if_not_exists`` parameters for all "Create" / "Drop" constructs including :class:`.CreateSequence`, :class:`.DropSequence`, :class:`.CreateIndex`, :class:`.DropIndex`, etc. allowing generic "IF EXISTS" / "IF NOT EXISTS" phrases to be rendered within DDL. Pull request courtesy Jesse Bakker. Fixes: #7354 Closes: #8492 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8492 Pull-request-sha: d107c6ce553bd430111607815f5b3938ffc4770c Change-Id: I367e57b2d9216f5180bcc44e86ca6f3dc794e5ca
* | clarify precedence docsMike Bayer2022-10-031-7/+14
| | | | | | | | | | Change-Id: I748f2736eb6382c8625b3419a82785b48766d8f7 references: #8584
* | the future is hereMike Bayer2022-10-026-23/+48
| | | | | | | | | | | | | | | | | | the autodoc for the "future" Engine / Connection were removed, so all these links weren't working. Replace all _future for these with _engine. There was just one _future pointing to select, changed that separately. Change-Id: Ib28270d8da8616b533953204e22eabee9388d620
* | run proxy doc generation for updated session methodsMike Bayer2022-09-302-13/+78
| | | | | | | | Change-Id: I0e86d78c2b56e8a1c85d5848b42a9eb4081bacfd
* | add autobuild; improve a few session docsMike Bayer2022-09-301-7/+48
|/ | | | | | | this is from the writeonly patch, some doc edits became more general so will backport these to 1.4. Change-Id: I19231e4bcfa33a0742c8995b6059c9a9488b1a6f
* Merge "Document user-defined functions for sqlite" into mainmike bayer2022-09-292-0/+41
|\
| * Document user-defined functions for sqliteGord Thompson2022-06-292-0/+41
| | | | | | | | Change-Id: I64e4d4dce8c5f5aced3190f9e3682c630462a61e
* | add "index", "unique" to Column.merge() attrsMike Bayer2022-09-261-0/+6
| | | | | | | | | | Fixes: #8578 Change-Id: Ic79c19748d5bb00353d0a97f3a4b4f5eb9fdbb0c
* | adjust for mypy 0.981Mike Bayer2022-09-262-3/+3
| | | | | | | | | | | | | | new release is out today, fix a very small number of new issues. Change-Id: I443c78f3384319d56deb2c9309118ffb750bbf41
* | Merge "add typing for sqlalchemy.orm.validates" into mainmike bayer2022-09-261-6/+8
|\ \
| * | add typing for sqlalchemy.orm.validatesMike Bayer2022-09-251-6/+8
| | | | | | | | | | | | | | | Fixes: #8577 Change-Id: Iede1c956078960fb866da45f1ac6aa43842516bc
* | | Merge "`aggregate_order_by` now supports cache generation." into mainmike bayer2022-09-262-1/+119
|\ \ \ | |/ / |/| |
| * | `aggregate_order_by` now supports cache generation.Federico Caselli2022-09-252-1/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | also adjusted CacheKeyFixture to be a general purpose fixture so that sub-components / dialects can run their own cache key tests. Fixes: #8574 Change-Id: I6c66107856aee11e548d357cea77bceee3e316a0
* | | Merge "New ORM Query Guide featuring DML support" into mainmike bayer2022-09-2617-331/+233
|\ \ \
| * | | New ORM Query Guide featuring DML supportMike Bayer2022-09-2517-331/+233
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | reviewers: these docs publish periodically at: https://docs.sqlalchemy.org/en/gerrit/4042/orm/queryguide/index.html See the "last generated" timestamp near the bottom of the page to ensure the latest version is up Change includes some other adjustments: * small typing fixes for end-user benefit * removal of a bunch of old examples for patterns that nobody uses or aren't really what we promote now * modernization of some examples, including inheritance Change-Id: I9929daab7797be9515f71c888b28af1209e789ff
* | | | Merge "ORM bulk insert via execute" into mainmike bayer2022-09-2625-700/+2317
|\ \ \ \ | |/ / /
| * | | ORM bulk insert via executeMike Bayer2022-09-2425-700/+2317
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ORM Insert now includes "bulk" mode that will run essentially the same process as session.bulk_insert_mappings; interprets the given list of values as ORM attributes for key names * ORM UPDATE has a similar feature, without RETURNING support, for session.bulk_update_mappings * Added support for upserts to do RETURNING ORM objects as well * ORM UPDATE/DELETE with list of parameters + WHERE criteria is a not implemented; use connection * ORM UPDATE/DELETE defaults to "auto" synchronize_session; use fetch if RETURNING is present, evaluate if not, as "fetch" is much more efficient (no expired object SELECT problem) and less error prone if RETURNING is available UPDATE: howver this is inefficient! please continue to use evaluate for simple cases, auto can move to fetch if criteria not evaluable * "Evaluate" criteria will now not preemptively unexpire and SELECT attributes that were individually expired. Instead, if evaluation of the criteria indicates that the necessary attrs were expired, we expire the object completely (delete) or expire the SET attrs unconditionally (update). This keeps the object in the same unloaded state where it will refresh those attrs on the next pass, for this generally unusual case. (originally #5664) * Core change! update/delete rowcount comes from len(rows) if RETURNING was used. SQLite at least otherwise did not support this. adjusted test_rowcount accordingly * ORM DELETE with a list of parameters at all is also a not implemented as this would imply "bulk", and there is no bulk_delete_mappings (could be, but we dont have that) * ORM insert().values() with single or multi-values translates key names based on ORM attribute names * ORM returning() implemented for insert, update, delete; explcit returning clauses now interpret rows in an ORM context, with support for qualifying loader options as well * session.bulk_insert_mappings() assigns polymorphic identity if not set. * explicit RETURNING + synchronize_session='fetch' is now supported with UPDATE and DELETE. * expanded return_defaults() to work with DELETE also. * added support for composite attributes to be present in the dictionaries used by bulk_insert_mappings and bulk_update_mappings, which is also the new ORM bulk insert/update feature, that will expand the composite values into their individual mapped attributes the way they'd be on a mapped instance. * bulk UPDATE supports "synchronize_session=evaluate", is the default. this does not apply to session.bulk_update_mappings, just the new version * both bulk UPDATE and bulk INSERT, the latter with or without RETURNING, support *heterogenous* parameter sets. session.bulk_insert/update_mappings did this, so this feature is maintained. now cursor result can be both horizontally and vertically spliced :) This is now a long story with a lot of options, which in itself is a problem to be able to document all of this in some way that makes sense. raising exceptions for use cases we haven't supported is pretty important here too, the tradition of letting unsupported things just not work is likely not a good idea at this point, though there are still many cases that aren't easily avoidable Fixes: #8360 Fixes: #7864 Fixes: #7865 Change-Id: Idf28379f8705e403a3c6a937f6a798a042ef2540
* | | | Merge "implement batched INSERT..VALUES () () for executemany" into mainmike bayer2022-09-2628-473/+1658
|\ \ \ \ | |/ / /
| * | | implement batched INSERT..VALUES () () for executemanyMike Bayer2022-09-2428-473/+1658
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the feature is enabled for all built in backends when RETURNING is used, except for Oracle that doesn't need it, and on psycopg2 and mssql+pyodbc it is used for all INSERT statements, not just those that use RETURNING. third party dialects would need to opt in to the new feature by setting use_insertmanyvalues to True. Also adds dialect-level guards against using returning with executemany where we dont have an implementation to suit it. execute single w/ returning still defers to the server without us checking. Fixes: #6047 Fixes: #7907 Change-Id: I3936d3c00003f02e322f2e43fb949d0e6e568304
* | | Merge "warn for local-only column in remote side" into mainmike bayer2022-09-251-0/+16
|\ \ \
| * | | warn for local-only column in remote sideMike Bayer2022-09-251-0/+16
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A warning is emitted in ORM configurations when an explicit :func:`_orm.remote` annotation is applied to columns that are local to the immediate mapped class, when the referenced class does not include any of the same table columns. Ideally this would raise an error at some point as it's not correct from a mapping point of view. Fixes: #7094 Fixes: #8575 Change-Id: Ia31be24aebe143161e19dc311b52c08fd5014d33
* | | Use aggregate order by instead of order by in subqueryFederico Caselli2022-09-251-25/+23
|/ / | | | | | | | | Fixes: #8561 Change-Id: I2d9f6bd895061bf8fbc66723930716670791d896
* | Merge "Tighten password security by removing `URL.__str__`" into mainmike bayer2022-09-243-6/+6
|\ \
| * | Tighten password security by removing `URL.__str__`Yassen Damyanov2022-09-233-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For improved security, the :class:`_url.URL` object will now use password obfuscation by default when ``str(url)`` is called. To stringify a URL with cleartext password, the :meth:`_url.URL.render_as_string` may be used, passing the :paramref:`_url.URL.render_as_string.hide_password` parameter as ``False``. Thanks to our contributors for this pull request. Fixes: #8567 Closes: #8563 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8563 Pull-request-sha: d1f1127f753849eb70b8d6cc64badf34e1b9219b Change-Id: If756c8073ff99ac83876d9833c8fe1d7c76211f9
* | | remove should_nest behavior for contains_eager()Mike Bayer2022-09-233-2/+21
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed regression for 1.4 in :func:`_orm.contains_eager` where the "wrap in subquery" logic of :func:`_orm.joinedload` would be inadvertently triggered for use of the :func:`_orm.contains_eager` function with similar statements (e.g. those that use ``distinct()``, ``limit()`` or ``offset()``). This is not appropriate for :func:`_orm.contains_eager` which has always had the contract that the user-defined SQL statement is unmodified with the exception of adding the appropriate columns. Also includes an adjustment to the assertion in Label._make_proxy() which was there to prevent a fixed label name from being anonymized; if the label is already anonymous, the change should proceed. This logic was being hit before the contains_eager behavior was adjusted. With the adjustment, this code is not used. Fixes: #8569 Change-Id: I161e65041c0162fd2b83cbef40f57a50fcfaf0fd
* | auto-cast PG range typesMike Bayer2022-09-204-5/+44
| | | | | | | | | | | | | | | | | | | | Range type handling has been enhanced so that it automatically renders type casts, so that in-place round trips for statements that don't provide the database with any context don't require the :func:`_sql.cast` construct to be explicit for the database to know the desired type. Change-Id: Id630b726f8a23059dd2f4cbc410bf5229d89cbfb References: #8540
* | Merge "break out text() from TextualSelect for col matching" into mainmike bayer2022-09-203-5/+30
|\ \
| * | break out text() from TextualSelect for col matchingMike Bayer2022-09-193-5/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where mixing "*" with additional explicitly-named column expressions within the columns clause of a :func:`_sql.select` construct would cause result-column targeting to sometimes consider the label name or other non-repeated names to be an ambiguous target. Fixes: #8536 Change-Id: I3c845eaf571033e54c9208762344f67f4351ac3a
* | | add raiseload to load_only()Mike Bayer2022-09-191-9/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | currently this can't be finessed in another way, at least not easily. The deferred() that it sets up doesn't seem to be cancellable. in any case, this is more consistent API with that of defer(). Change-Id: I30fca1cc371c9102d013cda8e23a522eea1033f8
* | | Merge "change verbiage stating exact compliance with RFC-1738" into mainmike bayer2022-09-171-14/+19
|\ \ \
| * | | change verbiage stating exact compliance with RFC-1738Mike Bayer2022-09-171-14/+19
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As long as we aren't using urlparse() to parse URLs, we are not RFC-1738 compliant. As we accept underscores in the scheme and not dashes or dots, we are not RFC-1738 compliant, so emulate language like that of PostgreSQL [1] that we "generally follow" this scheme but include some exceptions. [1] https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6 Fixes: #8519 Change-Id: I2d7e55d9df17aed122cebb2c4c315f56c06a3da5
* | | Improve array_agg and Array processingFederico Caselli2022-09-173-1/+16
|/ / | | | | | | | | | | | | | | | | The :class:`_functions.array_agg` will now set the array dimensions to 1. Improved :class:`_types.ARRAY` processing to accept ``None`` values as value of a multi-array. Fixes: #7083 Change-Id: Iafec4f77fde9719ccc7c8535bf6235dbfbc62102
* | Merge "Ignore max_overflow when pool_size is 0" into mainmike bayer2022-09-161-2/+2
|\ \
| * | Ignore max_overflow when pool_size is 0Federico Caselli2022-09-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | The :class:`_pool.QueuePool` now ignores ``max_overflow`` when ``pool_size=0``, properly making the pool unlimited in all cases. Fixes: #8523 Change-Id: Ifc32eb47a281c4b3acf357352f07b9b8a73d1b6f
* | | Merge "Support GROUP BY ROLLUP on MySql/MariaDB" into mainmike bayer2022-09-161-0/+6
|\ \ \
| * | | Support GROUP BY ROLLUP on MySql/MariaDBFederico Caselli2022-09-091-0/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | The ``ROLLUP`` function will now correctly render ``WITH ROLLUP`` on MySql and MariaDB, allowing the use of group by rollup with these backend. Fixes: #8503 Change-Id: I9289af3a39ca667a2f0f84f73346ebd4b091fedd
* | | Merge "catch exception for system_views also" into mainmike bayer2022-09-161-26/+28
|\ \ \
| * | | catch exception for system_views alsoMike Bayer2022-09-151-26/+28
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed yet another regression in SQL Server isolation level fetch (see :ticket:`8231`, :ticket:`8475`), this time with "Microsoft Dynamics CRM Database via Azure Active Directory", which apparently lacks the ``system_views`` view entirely. Error catching has been extended that under no circumstances will this method ever fail, provided database connectivity is present. Fixes: #8525 Change-Id: I76a429e3329926069a0367d2e77ca1124b9a059d