summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve typings of execution optionsFederico Caselli2022-11-023-53/+93
| | | | | Fixes: #8605 Change-Id: I4aec83b9f321462427c3f4ac941c3b272255c088
* correct typo in async postgresql uri (#8736)Yomain2022-11-021-1/+1
|
* further 2.0 modernizationsMike Bayer2022-10-131-0/+5
| | | | | | | biggest change here is the old tutorials were removed from the TOC and some additional links to them have been corrected. Change-Id: I79b878a946422eac24ed2449b440fc5d556576c4
* implement write-only colletions, typing for dynamicMike Bayer2022-10-061-149/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-053-3/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* the future is hereMike Bayer2022-10-022-16/+41
| | | | | | | | | 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-301-6/+31
| | | | Change-Id: I0e86d78c2b56e8a1c85d5848b42a9eb4081bacfd
* adjust for mypy 0.981Mike Bayer2022-09-261-1/+1
| | | | | | | new release is out today, fix a very small number of new issues. Change-Id: I443c78f3384319d56deb2c9309118ffb750bbf41
* Improved usage of ``asyncio.shield()``Federico Caselli2022-09-152-4/+8
| | | | | Fixes: #8516 Change-Id: Ifd8f5e5f42d9fbcd5b8d00bddc81ff6be690a75e
* implement event for merge/load=False for mutable state setupMike Bayer2022-08-301-0/+8
| | | | | | | | | | | | | Fixed issue in :mod:`sqlalchemy.ext.mutable` extension where collection links to the parent object would be lost if the object were merged with :meth:`.Session.merge` while also passing :paramref:`.Session.merge.load` as False. The event added here is currently private for expediency, but is acceptable to become a public event at some point. Fixes: #8446 Change-Id: I9e5b9f1f5a0c5a9781f51635d5e57b1134c9e866
* improve abstractconcretebaseMike Bayer2022-08-181-13/+47
| | | | | | | | | | | | | | | | | try to limit the attributes on the base and set up wpoly etc so that things still work the way we want. It seems like I've tried this in the past before so not sure if this is actually working or if there are problems. it needs a little more strictness on how you set up your base since attributes are no longer implicit. So, it seems like perhaps the new behavior should be on a flag or something like "strict_attributes=True", something like that, so that nothing breaks for existing users and we can slowly deal with the new way being a little bit less worse than the old way. Fixes: #8403 Change-Id: Ic9652d9a0b024d649807aaf3505e67173e7dc3b9
* more abstractconcretebase clarityMike Bayer2022-08-181-22/+23
| | | | Change-Id: I9ddb6b1a2e0c0be1fe355a7ea714d0e16aa93b47
* Update to flake8 5.Federico Caselli2022-07-312-7/+9
| | | | Change-Id: I5a241a70efba68bcea9819ddce6aebc25703e68d
* Remove all `__nonzero__` methods (#8308)Nikita Sobolev2022-07-301-4/+0
|
* 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
* | 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
* | update ORM declarative docs for new featuresMike Bayer2022-07-161-40/+40
| | | | | | | | | | | | | | I screwed up a rebase or something so this was temporarily in Ic51a12de3358f3a451bd7cf3542b375569499fc1 Change-Id: I847ee1336381221c0112b67854df022edf596b25
* | support dataclasses with MutableCompositeMike Bayer2022-07-131-1/+2
| | | | | | | | | | | | basically a one line change Change-Id: If6a70d49777e77f86e2b6936dd4aece20b00708e
* | Merge "Support lambda expression in mypy plugin" into mainmike bayer2022-07-041-0/+5
|\ \
| * | Support lambda expression in mypy pluginCyril Chapellier2022-07-021-0/+5
| | | | | | | | | | | | | | | | | | | | | Avoid `error: INTERNAL ERROR` when the default is a lambda Fixes: #8196 Change-Id: I7346c693519b024c56156db6f4ffc9a45bb748d3
* | | repair yield_per for non-SS dialects and add new optionsMike Bayer2022-07-011-0/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implemented new :paramref:`_engine.Connection.execution_options.yield_per` execution option for :class:`_engine.Connection` in Core, to mirror that of the same :ref:`yield_per <orm_queryguide_yield_per>` option available in the ORM. The option sets both the :paramref:`_engine.Connection.execution_options.stream_results` option at the same time as invoking :meth:`_engine.Result.yield_per`, to provide the most common streaming result configuration which also mirrors that of the ORM use case in its usage pattern. Fixed bug in :class:`_engine.Result` where the usage of a buffered result strategy would not be used if the dialect in use did not support an explicit "server side cursor" setting, when using :paramref:`_engine.Connection.execution_options.stream_results`. This is in error as DBAPIs such as that of SQLite and Oracle already use a non-buffered result fetching scheme, which still benefits from usage of partial result fetching. The "buffered" strategy is now used in all cases where :paramref:`_engine.Connection.execution_options.stream_results` is set. Added :meth:`.FilterResult.yield_per` so that result implementations such as :class:`.MappingResult`, :class:`.ScalarResult` and :class:`.AsyncResult` have access to this method. Fixes: #8199 Change-Id: I6dde3cbe483a1bf81e945561b60f4b7d1c434750
* | add fallback for old mutable formatMike Bayer2022-06-241-2/+8
| | | | | | | | | | | | | | | | | | | | | | Fixed regression caused by :ticket:`8133` where the pickle format for mutable attributes was changed, without a fallback to recognize the old format, causing in-place upgrades of SQLAlchemy to no longer be able to read pickled data from previous versions. A check plus a fallback for the old format is now in place. Fixes: #8133 Change-Id: I9029729b4bc56c8b3145797869229eeff48a3b3b
* | use metadata.reflect() for DeferredReflectionMike Bayer2022-06-211-32/+55
| | | | | | | | | | | | | | | | | | as metadata.reflect() now has a signficant performance gain over indivdual Table reflection, rework DeferredReflection to use this Fixes: #8155 Change-Id: I98d55fae83f0cf06a8ca8b89112c85655424d73a
* | rework ORM mapping docsMike Bayer2022-06-212-2/+17
|/ | | | | | | | | | prepare docs for newly incoming mapper styles, including new dataclass mapping. move the existing dataclass/attrs docs all into their own section and try to improve organization and wording into the relatively recent "mapping styles" document. Change-Id: I0b5e2a5b6a70db65ab19b5bb0a2bb7df20e0b498
* Merge "pickle mutable parents according to key" into mainmike bayer2022-06-151-3/+4
|\
| * pickle mutable parents according to keyMike Bayer2022-06-141-3/+4
| | | | | | | | | | | | | | | | | | Fixed bug in :class:`.Mutable` where pickling and unpickling of an ORM mapped instance would not correctly restore state for mappings that contained multiple :class:`.Mutable`-enabled attributes. Fixes: #8133 Change-Id: I508763e0df0d7a624e1169f9a46d7f25404add1e
* | Remove reflect=True in Base.prepare examplesGord Thompson2022-06-141-8/+8
|/ | | | Change-Id: Icdb17fab0f92762a266efbe1a64bec1d5a6dc9ab
* Merge "migrate labels to new tutorial" into mainmike bayer2022-06-071-1/+1
|\
| * migrate labels to new tutorialMike Bayer2022-06-071-1/+1
| | | | | | | | | | | | | | other org changes and some sections from old tutorial ported to new tutorial. Change-Id: Ic0fba60ec82fff481890887beef9ed0fa271875a
* | Merge "Generalize RETURNING and suppor for MariaDB / SQLite" into mainmike bayer2022-06-051-1/+0
|\ \
| * | Generalize RETURNING and suppor for MariaDB / SQLiteDaniel Black2022-06-021-1/+0
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As almost every dialect supports RETURNING now, RETURNING is also made more of a default assumption. * the default compiler generates a RETURNING clause now when specified; CompileError is no longer raised. * The dialect-level implicit_returning parameter now has no effect. It's not fully clear if there are real world cases relying on the dialect-level parameter, so we will see once 2.0 is released. ORM-level RETURNING can be disabled at the table level, and perhaps "implicit returning" should become an ORM-level option at some point as that's where it applies. * Altered ORM update() / delete() to respect table-level implicit returning for fetch. * Since MariaDB doesnt support UPDATE returning, "full_returning" is now split into insert_returning, update_returning, delete_returning * Crazy new thing. Dialects that have *both* cursor.lastrowid *and* returning. so now we can pick between them for SQLite and mariadb. so, we are trying to keep it on .lastrowid for simple inserts with an autoincrement column, this helps with some edge case test scenarios and i bet .lastrowid is faster anyway. any return_defaults() / multiparams etc then we use returning * SQLite decided they dont want to return rows that match in ON CONFLICT. this is flat out wrong, but for now we need to work with it. Fixes: #6195 Fixes: #7011 Closes: #7047 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7047 Pull-request-sha: d25d5ea3abe094f282c53c7dd87f5f53a9e85248 Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I9908ce0ff7bdc50bd5b27722081767c31c19a950
* | Docs Update - Add **kwargs to CaseInsensitiveComparator docs (#8063)Justin Crown2022-06-041-9/+15
|/ | | | | | | | | | | | | * Add **kwargs to CaseInsensitiveComparator docs * add kwargs to other operate examples Change-Id: I70a1e68bca27c2355ad3b7c5bbc538027f112bd9 * missed one entry Change-Id: Ieb4a18ab6d96e588e9ec7672cfa65fe2fd8301e5 Co-authored-by: Federico Caselli <cfederico87@gmail.com>
* establish sessionmaker and async_sessionmaker as genericMike Bayer2022-05-313-29/+39
| | | | | | | | | | | This is so that custom Session and AsyncSession classes can be typed for these factories. Added appropriate typevars to `__call__()`, `__enter__()` and other methods so that a custom Session or AsyncSession subclass is carried through. Fixes: #7656 Change-Id: Ia2b8c1f22b4410db26005c3285f6ba3d13d7f0e0
* fix most sphinx warnings (1.4)Mike Bayer2022-05-161-2/+2
| | | | | | | | | | | | | | | still can't figure out the warnings with some of the older changelog files. this cherry-picks the sphinx fixes from 1.4 and additionally fixes a small number of new issues in the 2.0 docs. However, 2.0 has many more errors to fix, primarily from the removal of the legacy tutorials left behind a lot of labels that need to be re-linked to the new tutorial. Fixes: #7946 Change-Id: Id657ab23008eed0b133fed65b2f9ea75a626215c (cherry picked from commit 9b55a423459236ca8a2ced713c9e93999dd18922)
* revenge of pep 484Mike Bayer2022-05-153-26/+51
| | | | | | trying to get remaining must-haves for ORM Change-Id: I66a3ecbbb8e5ba37c818c8a92737b576ecf012f7
* update for flake8-future-imports 0.0.5Mike Bayer2022-05-141-2/+0
| | | | | | | | a whole bunch of errors were apparently blocked by 0.0.4 being installed. Fixes: #8020 Change-Id: I22a0faeaabe03de501897893391946d677c2df7e
* run zimports to match pref changesMike Bayer2022-05-061-1/+0
| | | | | | | I've turned "remove unused imports" back on so this affects some not-used imports in TYPE_CHECKING blocks Change-Id: I8b64ff4ec63f4cee01c2bf41399b691e1c3fb04a
* pep484: attributes and relatedMike Bayer2022-05-031-6/+7
| | | | | | | also implements __slots__ for QueryableAttribute, InstrumentedAttribute, Relationship.Comparator. Change-Id: I47e823160706fc35a616f1179a06c7864089e5b5
* inline mypy config; files ignoring type errors for the momentMike Bayer2022-04-2813-1/+31
| | | | | | | | | | | | | | | | | | | to simplify pyproject.toml change the remaining files that aren't going to be typed on this first pass (unless of course someone wants to type some of these) to include # mypy: ignore-errors. for the moment, only a handful of ORM modules are to have more type checking implemented. It's important that ignore-errors is used and not "# type: ignore", as in the latter case, mypy doesn't even read the existing types in the file, which makes it impossible to type any files that refer to those modules at all. to simplify ongoing typing work use inline mypy config for remaining files that are "done" for now, indicating the level of type checking they currently have. Change-Id: I98669c1a305c2f0adba85d10b5425541f3fe9533
* pep484 ORM / SQL result supportMike Bayer2022-04-275-45/+700
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after some experimentation it seems mypy is more amenable to the generic types being fully integrated rather than having separate spin-off types. so key structures like Result, Row, Select become generic. For DML Insert, Update, Delete, these are spun into type-specific subclasses ReturningInsert, ReturningUpdate, ReturningDelete, which is fine since the "row-ness" of these constructs doesn't happen until returning() is called in any case. a Tuple based model is then integrated so that these objects can carry along information about their return types. Overloads at the .execute() level carry through the Tuple from the invoked object to the result. To suit the issue of AliasedClass generating attributes that are dynamic, experimented with a custom subclass AsAliased, but then just settled on having aliased() lie to the type checker and return `Type[_O]`, essentially. will need some type-related accessors for with_polymorphic() also. Additionally, identified an issue in Update when used "mysql style" against a join(), it basically doesn't work if asked to UPDATE two tables on the same column name. added an error message to the specific condition where it happens with a very non-specific error message that we hit a thing we can't do right now, suggest multi-table update as a possible cause. Change-Id: I5eff7eefe1d6166ee74160b2785c5e6a81fa8b95
* pep-484: ORM public API, constructorsMike Bayer2022-04-203-51/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for the moment, abandoning using @overload with relationship() and mapped_column(). The overloads are very difficult to get working at all, and the overloads that were there all wouldn't pass on mypy. various techniques of getting them to "work", meaning having right hand side dictate what's legal on the left, have mixed success and wont give consistent results; additionally, it's legal to have Optional / non-optional independent of nullable in any case for columns. relationship cases are less ambiguous but mypy was not going along with things. we have a comprehensive system of allowing left side annotations to drive the right side, in the absense of explicit settings on the right. so type-centric SQLAlchemy will be left-side driven just like dataclasses, and the various flags and switches on the right side will just not be needed very much. in other matters, one surprise, forgot to remove string support from orm.join(A, B, "somename") or do deprecations for it in 1.4. This is a really not-directly-used structure barely mentioned in the docs for many years, the example shows a relationship being used, not a string, so we will just change it to raise the usual error here. Change-Id: Iefbbb8d34548b538023890ab8b7c9a5d9496ec6e
* mypy .950 updatesMike Bayer2022-04-171-2/+2
| | | | | Fixes: #7942 Change-Id: Ice1243e1704e88bb8fa13fb0d1f8e24dcd94bfd4
* pep484: schema APIMike Bayer2022-04-157-21/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | implement strict typing for schema.py this module has lots of public API, lots of old decisions and very hard to follow construction sequences in many cases, and is also where we get a lot of new feature requests, so strict typing should help keep things clean. among improvements here, fixed the pool .info getters and also figured out how to get ColumnCollection and related to be covariant so that we may set them up as returning Column or ColumnClause without any conflicts. DDL was affected, noting that superclasses of DDLElement (_DDLCompiles, added recently) can now be passed into "ddl_if" callables; reorganized ddl into ExecutableDDLElement as a new name for DDLElement and _DDLCompiles renamed to BaseDDLElement. setting up strict also located an API use case that is completely broken, which is connection.execute(some_default) returns a scalar value. This case has been deprecated and new paths have been set up so that connection.scalar() may be used. This likely wasn't possible in previous versions because scalar() would assume a CursorResult. The scalar() change also impacts Session as we have explicit support (since someone had reported it as a regression) for session.execute(Sequence()) to work. They will get the same deprecation message (which omits the word "Connection", just uses ".execute()" and ".scalar()") and they can then use Session.scalar() as well. Getting this to type correctly while still supporting ORM use cases required some refactoring, and I also set up a keyword only delimeter for Session.execute() and related as execution_options / bind_arguments should always be keyword only, applied these changes to AsyncSession as well. Additionally simpify Table __init__ now that we are Python 3 only, we can have positional plus explicit kwargs finally. Simplify Column.__init__ as well again taking advantage of kw only arguments. Fill in most/all __init__ methods in sqltypes.py as the constructor for types is most of the API. should likely do this for dialect-specific types as well. Apply _InfoType for all info attributes as should have been done originally and update descriptor decorators. Change-Id: I3f9f8ff3f1c8858471ff4545ac83d68c88107527
* pep-484: asyncioMike Bayer2022-04-117-463/+956
| | | | | | | | | | | | | | | | | | | | | in this patch the asyncio/events.py module, which existed only to raise errors when trying to attach event listeners, is removed, as we were already coding an asyncio-specific workaround in upstream Pool / Session to raise this error, just moved the error out to the target and did the same thing for Engine. We also add an async_sessionmaker class. The initial rationale here is because sessionmaker() is hardcoded to Session subclasses, and there's not a way to get the use case of sessionmaker(class_=AsyncSession) to type correctly without changing the sessionmaker() symbol itself to be a function and not a class, which gets too complicated for what this is. Additionally, _SessionClassMethods has only three methods on it, one of which is not usable with asyncio (close_all()), the others not generally used from the session class. Change-Id: I064a5fa5d91cc8d5bbe9597437536e37b4e801fe
* pep-484: session, instancestate, etcMike Bayer2022-04-123-38/+48
| | | | | | | | Also adds some fixes to annotation-based mapping that have come up, as well as starts to add more pep-484 test cases Change-Id: Ia722bbbc7967a11b23b66c8084eb61df9d233fee
* use code generation for scoped_sessionMike Bayer2022-04-123-3/+1903
| | | | | | | | | | | | | | | | | | | our decorator thing generates code in any case, so point it at the file itself to generate real code for the blocks rather than doing things dynamically. this will allow typing tools to have no problem whatsoever and we also reduce import time overhead. file size will be a lot bigger though, shrugs. syntax / dupe method / etc. checking will be accomplished by our existing linting / typing / formatting tools. As we are also using "from __future__ import annotations", we also no longer have to apply quotes to generated annotations. Change-Id: I20962cb65bda63ff0fb67357ab346e9b1ef4f108
* level up pep-484 on engine resultMike Bayer2022-04-121-17/+19
| | | | | | | | | | Have each result subclass be generic to the kind of row/object it returns. rework things so that a significant number of "type ignores" can go away and also allow asyncio to more cleanly proxy the result objects. Change-Id: Ia3ddb2cb52f5856839bd8c9c46f0289ab4b10405
* update flake8 noqa skips with proper syntaxFederico Caselli2022-04-113-5/+5
| | | | Change-Id: I42ed77f559e3ee5b8c600d98457ee37803ef0ea6
* update DDL examples removing execute_ifMike Bayer2022-04-091-6/+13
| | | | | Fixes: #7924 Change-Id: I684bf3720010ffe34dbdd39ec8c7e0c4af94e620