summaryrefslogtreecommitdiff
path: root/test/ext
Commit message (Collapse)AuthorAgeFilesLines
* Add async tests to the github workflowworkflow_test_aiosqliteFederico Caselli2021-09-061-0/+1
| | | | | Fixes: #6967 Change-Id: I222cb5bdedf572e734c827d72bcbced202cdd62f
* add asyncio.gather() example; add connection optsMike Bayer2021-09-021-0/+11
| | | | | | | | | | | | while I dont like this approach very much, people will likely be asking for it a lot, so represent the most correct and efficient form we can handle right now. Added missing ``**kw`` arguments to the :meth:`_asyncio.AsyncSession.connection` method. Change-Id: Idadae2a02a4d96ecb96a5723ce64d017ab4c6217 References: https://github.com/sqlalchemy/sqlalchemy/discussions/6965
* Merge "Allow custom sync session class in ``AsyncSession``."mike bayer2021-08-301-4/+46
|\
| * Allow custom sync session class in ``AsyncSession``.Federico Caselli2021-08-301-4/+46
| | | | | | | | | | | | | | | | | | | | | | The :class:`_asyncio.AsyncSession` now supports overriding which :class:`_orm.Session` it uses as the proxied instance. A custom ``Session`` class can be passed using the :paramref:`.AsyncSession.sync_session_class` parameter or by subclassing the ``AsyncSession`` and specifying a custom :attr:`.AsyncSession.sync_session_class`. Fixes: #6689 Change-Id: Idf9c24eae6c9f4e2fff292ed748feaa449a8deaa
* | Improve error message when inspecting async proxiesFederico Caselli2021-08-302-5/+38
|/ | | | | | | Provide better error message when trying to insepct and async engine or asnyc connection. Change-Id: I907f3a22c6b76fe43df9d40cb0e69c57f74a7982
* Merge "dont assume argument lists for column property"mike bayer2021-08-281-0/+32
|\
| * dont assume argument lists for column propertyMike Bayer2021-08-271-0/+32
| | | | | | | | | | | | | | | | Fixed issue where mypy plugin would crash when interpreting a ``query_expression()`` construct. Fixes: #6950 Change-Id: Ic1f28d135bf6eb05c92061430c0d5a3663b804ef
* | Handle mappings passed to ``execution_options``.Federico Caselli2021-08-261-4/+10
|/ | | | | | | | | | Fixed a bug in :meth:`_asyncio.AsyncSession.execute` and :meth:`_asyncio.AsyncSession.stream` that required ``execution_options`` to be an instance of ``immutabledict`` when defined. It now correctly accepts any mapping. Fixes: #6943 Change-Id: Ic09de480dc2da1b0bdce25acb60b8f01371971f9
* ensure "sqlalchemy" info set for all considered classesMike Bayer2021-08-251-0/+27
| | | | | | | | | Fixed issue in mypy plugin where columns on a mixin would not be correctly interpreted if the mapped class relied upon a ``__tablename__`` routine that came from a superclass. Fixes: #6937 Change-Id: I74aed4862d0545008ee67f781aaa794ab6866926
* Merge "Refactor mypy plugin"mike bayer2021-08-071-0/+41
|\
| * Refactor mypy pluginBryan Forbes2021-08-071-0/+41
| | | | | | | | | | | | | | | | | | | | A major refactor of the mypy plugin Closes: #6764 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6764 Pull-request-sha: 3e2295b2da7b57a6669f26db0df78f6409934184 Change-Id: I067d56dcfbc998ddd1b22a448f756859428b9e31
* | Merge "Modernize tests - dml_values"mike bayer2021-08-071-1/+3
|\ \
| * | Modernize tests - dml_valuesGord Thompson2021-07-261-1/+3
| | | | | | | | | | | | Change-Id: Ida86ed40c43d91813151621b847376976773a5f9
* | | Merge "Fix type"mike bayer2021-07-291-1/+2
|\ \ \
| * | | Fix typeKazantcev Andrey2021-07-221-1/+2
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | https://github.com/sqlalchemy/sqlalchemy2-stubs/pull/132#issuecomment-883159494 Closes: #6789 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6789 Pull-request-sha: 36e9075a8ee0ff699deea8ceef6e72ed4bc1d854 Change-Id: I87fe210b5d69c1e2500fb8e1440592ff44ceaacf
* | | accommodate plain core textual statementsMike Bayer2021-07-271-1/+32
| |/ |/| | | | | | | | | | | | | | | Fixed issue where the horizontal sharding extension would not correctly accommodate for a plain textual SQL statement passed to :meth:`_orm.Session.execute`. Fixes: #6816 Change-Id: Ie2b71b06d10793443dbd5e1b271c56cbf9431bb3
* | Add mypy tests on github.Federico Caselli2021-07-222-1/+15
|/ | | | | | Support skipping mypy tests based on interpreter version Change-Id: I98963318dbb2e7e097ad5518e0e4022349ca9779
* Merge "labeling refactor"mike bayer2021-07-131-8/+4
|\
| * labeling refactorMike Bayer2021-07-121-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To service #6718 and #6710, the system by which columns are given labels in a SELECT statement as well as the system that gives them keys in a .c or .selected_columns collection have been refactored to provide a single source of truth for both, in constrast to the previous approach that included similar logic repeated in slightly different ways. Main ideas: 1. ColumnElement attributes ._label, ._anon_label, ._key_label are renamed to include the letters "tq", meaning "table-qualified" - these labels are only used when rendering a SELECT that has LABEL_STYLE_TABLENAME_PLUS_COL for its label style; as this label style is primarily legacy, the "tq" names should be isolated so that in a 2.0 style application these aren't being used at all 2. The means by which the "labels" and "proxy keys" for the elements of a SELECT has been centralized to a single source of truth; previously, the three of _generate_columns_plus_names, _generate_fromclause_column_proxies, and _column_naming_convention all had duplicated rules between them, as well as that there were a little bit of labeling rules in compiler._label_select_column as well; by this we mean that the various "anon_label" "anon_key" methods on ColumnElement were called by all four of these methods, where there were many cases where it was necessary that one method comes up with the same answer as another of the methods. This has all been centralized into _generate_columns_plus_names for all the names except the "proxy key", which is generated by _column_naming_convention. 3. compiler._label_select_column has been rewritten to both not make any naming decisions nor any "proxy key" decisions, only whether to label or not to label; the _generate_columns_plus_names method gives it the information, where the proxy keys come from _column_naming_convention; previously, these proxy keys were matched based on restatement of similar (but not really the same) logic in two places. The heuristics of "whether to label or not to label" are also reorganized to be much easier to read and understand. 4. a new method compiler._label_returning_column is added for dialects to use in their "generate returning columns" methods. A github search reveals a small number of third party dialects also doing this using the prior _label_select_column method so we try to make sure _label_select_column continues to work the exact same way for that specific use case; for the "SELECT" use case it now needs 5. After some attempts to do it different ways, for the case where _proxy_key is giving us some kind of anon label, we are hard changing it to "_no_label" right now, as there's not currently a way to fully match anonymized labels from stmt.c or stmt.selected_columns to what will be in the result map. The idea of "_no_label" is to encourage the user to use label('name') for columns they want to be able to target by string name that don't have a natural name. Change-Id: I7a92a66f3a7e459ccf32587ac0a3c306650daf11
* | Merge "implement deferred scalarobject history load"mike bayer2021-07-101-0/+90
|\ \ | |/ |/|
| * implement deferred scalarobject history loadMike Bayer2021-07-091-0/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modified the approach used for history tracking of scalar object relationships that are not many-to-one, i.e. one-to-one relationships that would otherwise be one-to-many. When replacing a one-to-one value, the "old" value that would be replaced is no longer loaded immediately, and is instead handled during the flush process. This eliminates an historically troublesome lazy load that otherwise often occurs when assigning to a one-to-one attribute, and is particularly troublesome when using "lazy='raise'" as well as asyncio use cases. This change does cause a behavioral change within the :meth:`_orm.AttributeEvents.set` event, which is nonetheless currently documented, which is that the event applied to such a one-to-one attribute will no longer receive the "old" parameter if it is unloaded and the :paramref:`_orm.relationship.active_history` flag is not set. As is documented in :meth:`_orm.AttributeEvents.set`, if the event handler needs to receive the "old" value when the event fires off, the active_history flag must be established either with the event listener or with the relationship. This is already the behavior with other kinds of attributes such as many-to-one and column value references. The change additionally will defer updating a backref on the "old" value in the less common case that the "old" value is locally present in the session, but isn't loaded on the relationship in question, until the next flush occurs. If this causes an issue, again the normal :paramref:`_orm.relationship.active_history` flag can be set to ``True`` on the relationship. A private flag which restores the old value is retained for now, as support within relevant test suites to exercise the old and new behaviors together. This is so that if the behavioral change produces problems we have test harnesses set up to further examine these behaviors. The "legacy" style can go away in 2.0 or in a much later 1.4 release. Fixes: #6708 Change-Id: Id7f72fc39dcbec9119b665e528667a9919bb73b4
* | Merge "Add additional support to honor _proxy_key in Core selects"mike bayer2021-07-091-0/+88
|\ \
| * | Add additional support to honor _proxy_key in Core selectsMike Bayer2021-07-051-0/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed ORM regression where ad-hoc label names generated for hybrid properties and potentially other similar types of ORM-enabled expressions would usually be propagated outwards through subqueries, allowing the name to be retained in the final keys of the result set even when selecting from subqueries. Additional state is now tracked in this case that isn't lost when a hybrid is selected out of a Core select / subquery. as we have removed things like column.label() from ORM, since we now have to export the cols with the same names as what we will render, experiment with giving a greater role to the _proxy_key annotation so that a desired name can be carried through more transarently. Fixes: #6718 Change-Id: Icb313244c13ea1a8f58d3e05d07aa3e1039e15bf
* | | Replace all http:// links to https://Federico Caselli2021-07-041-1/+1
|/ / | | | | | | | | | | Also replace http://pypi.python.org/pypi with https://pypi.org/project Change-Id: I84b5005c39969a82140706472989f2a30b0c7685
* | Modernize testsGord Thompson2021-07-031-2/+2
|/ | | | | | Eliminate engine.execute() and engine.scalar() Change-Id: I99f76d0e615ddebab2da4fd07a40a0a2796995c7
* have automap suppress overlaps warning for mapped secondaryMike Bayer2021-06-251-0/+41
| | | | | | | | | | | | | | | | Fixed regression in :mod:`sqlalchemy.ext.automap` extension such that the use case of creating an explicit mapped class to a table that is also the :paramref:`_orm.relationship.secondary` element of a :func:`_orm.relationship` that automap will be generating would emit the "overlaps" warnings introduced in 1.4 and discussed at :ref:`error_qzyx`. While generating this case from automap is still subject to the same caveats that the "overlaps" warning refers towards, as automap is intended for more ad-hoc use cases, the condition which produces the warning is disabled when a many-to-many relationship with this particular pattern is generated. Fixes: #6679 Change-Id: Ib3a53982b076ed4999b0d3235f84008b9e2f1cce
* adjust patchfile from 6ca7c2ebMike Bayer2021-06-211-4/+5
| | | | | | | code formatting modified table.py such that the patchfile would no longer apply and this was missed in review. Change-Id: I0af91cf92baa79f196b4d9f3af1bab3bb0984a23
* accommodate no cls info found in _scan_declarativeMike Bayer2021-06-214-0/+20
| | | | | | | | | Fixed issue in mypy plugin where class info for a custom declarative base would not be handled correctly on a cached mypy pass, leading to an AssertionError being raised. Fixes: #6476 Change-Id: If78340673e6a4d16d8f7cf787ce3bdb02c8bd47b
* pin async scoping tests at python 3.7Mike Bayer2021-06-161-2/+4
| | | | | | as it relies upon asyncio.current_task that's not in 3.6 Change-Id: I2b09295bf736811f260640102214a531c9b9e816
* Implement async_scoped_sessionjason3gb2021-06-161-0/+44
| | | | | | | | | | | | | | | Implemented :class:`_asyncio.async_scoped_session` to address some asyncio-related incompatibilities between :class:`_orm.scoped_session` and :class:`_asyncio.AsyncSession`, in which some methods (notably the :meth:`_asyncio.async_scoped_session.remove` method) should be used with the ``await`` keyword. Fixes: #6583 Closes: #6603 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6603 Pull-request-sha: 0e8ef87dc824dcd83dca01641441afc453c8e07a Change-Id: I9bfe56f8670302ff0015d9dc56c1e3ac5b92b118
* Propagate asyncio flag from the dialect to selected pool classesFederico Caselli2021-06-081-9/+6
| | | | | | | | | Fixed an issue that presented itself when using the :class:`_pool.NullPool` or the :class:`_pool.StaticPool` with an async engine. This mostly affected the aiosqlite dialect. Fixes: #6575 Change-Id: Ic1e27d99ffcb20ed4de82ea78f430a0f3b629d86
* Merge "Implement proxy back reference system for asyncio"mike bayer2021-06-032-2/+279
|\
| * Implement proxy back reference system for asyncioMike Bayer2021-06-022-2/+279
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implemented a new registry architecture that allows the ``Async`` version of an object, like ``AsyncSession``, ``AsyncConnection``, etc., to be locatable given the proxied "sync" object, i.e. ``Session``, ``Connection``. Previously, to the degree such lookup functions were used, an ``Async`` object would be re-created each time, which was less than ideal as the identity and state of the "async" object would not be preserved across calls. From there, new helper functions :func:`_asyncio.async_object_session`, :func:`_asyncio.async_session` as well as a new :class:`_orm.InstanceState` attribute :attr:`_orm.InstanceState.asyncio_session` have been added, which are used to retrieve the original :class:`_asyncio.AsyncSession` associated with an ORM mapped object, a :class:`_orm.Session` associated with an :class:`_asyncio.AsyncSession`, and an :class:`_asyncio.AsyncSession` associated with an :class:`_orm.InstanceState`, respectively. This patch also implements new methods :meth:`_asyncio.AsyncSession.in_nested_transaction`, :meth:`_asyncio.AsyncSession.get_transaction`, :meth:`_asyncio.AsyncSession.get_nested_transaction`. Fixes: #6319 Change-Id: Ia452a7e7ce9bad3ff8846c7dea8d45c839ac9fac
* | temporarily disable test_no_attach_to_event_loopMike Bayer2021-06-021-1/+7
|/ | | | | | | | | | | | | | this test currently causes the test suite to hang; it previously was not actually running the worker thread as the testing_engine() fixture was rejecting the "transfer_staticpool" keyword argument. as we seem to have a greenlet-related segfault in 3.10.0b2 I am going to have to get the greenlet devs to run the test suite so i want to get anything not totally smooth out of it for the moment. Change-Id: Ib453d0bc23ca013598bc80ff29e5da496771d5b1
* Ensure extended instrumentation is fully disposedMike Bayer2021-05-201-0/+47
| | | | | | | | | | | | | Fixed regression in the ``sqlalchemy.ext.instrumentation`` extension that prevented instrumentation disposal from working completely. This fix includes both a 1.4 regression fix as well as a fix for a related issue that existed in 1.3 also. As part of this change, the :class:`sqlalchemy.ext.instrumentation.InstrumentationManager` class now has a new method ``unregister()``, which replaces the previous method ``dispose()``, which was not called as of version 1.4. Fixes: #6390 Change-Id: I1b7a0f190b56d31b93b5ba11f67dc9f73889958b
* Update black flak8 and zimportsFederico Caselli2021-05-123-4/+5
| | | | Change-Id: I488c9557eda390e4a88319affd4c8813ee274f80
* Merge "don't cache TypeDecorator by default"mike bayer2021-05-062-0/+5
|\
| * don't cache TypeDecorator by defaultMike Bayer2021-05-062-0/+5
| | | | | | | | | | | | | | | | | | | | The :class:`.TypeDecorator` class will now emit a warning when used in SQL compilation with caching unless the ``.cache_ok`` flag is set to ``True`` or ``False``. ``.cache_ok`` indicates that all the parameters passed to the object are safe to be used as a cache key, ``False`` means they are not. Fixes: #6436 Change-Id: Ib1bb7dc4b124e38521d615c2e2e691e4915594fb
* | Merge "mypy: fix working directory for mypy_extra_test_paths."mike bayer2021-05-061-21/+7
|\ \
| * | mypy: fix working directory for mypy_extra_test_paths.Maico Timmerman2021-05-051-21/+7
| |/ | | | | | | Change-Id: I55f6b414dd6893590231cc929648db90d3ee4161
* | Merge "unify transactional context managers"mike bayer2021-05-062-2/+148
|\ \ | |/ |/|
| * unify transactional context managersMike Bayer2021-05-052-2/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Applied consistent behavior to the use case of calling ``.commit()`` or ``.rollback()`` inside of an existing ``.begin()`` context manager, with the addition of potentially emitting SQL within the block subsequent to the commit or rollback. This change continues upon the change first added in :ticket:`6155` where the use case of calling "rollback" inside of a ``.begin()`` contextmanager block was proposed: * calling ``.commit()`` or ``.rollback()`` will now be allowed without error or warning within all scopes, including that of legacy and future :class:`_engine.Engine`, ORM :class:`_orm.Session`, asyncio :class:`.AsyncEngine`. Previously, the :class:`_orm.Session` disallowed this. * The remaining scope of the context manager is then closed; when the block ends, a check is emitted to see if the transaction was already ended, and if so the block returns without action. * It will now raise **an error** if subsequent SQL of any kind is emitted within the block, **after** ``.commit()`` or ``.rollback()`` is called. The block should be closed as the state of the executable object would otherwise be undefined in this state. Fixes: #6288 Change-Id: I8b21766ae430f0fa1ac5ef689f4c0fb19fc84336
* | mypy: load extra test files from environment variableMaico Timmerman2021-05-041-16/+39
|/ | | | | | | | | | Add --mypy-extra-test-path parameter to pytest execution to list extra directories to load test files from. This enables the stubs repo to load this plugin and specify it's own test directory to run mypy tests. Supports both single file tests and incremental tests based on patch files. Change-Id: Id6424ff15b2f527183b9713384df3d625a8e6eb8
* Avoid creating asyncio.Lock on the wrong loop.Federico Caselli2021-05-011-0/+37
| | | | | | | | | | | Fixed a regression introduced by :ticket:`6337` that would create an ``asyncio.Lock`` which could be attached to the wrong loop when instantiating the async engine before any asyncio loop was started, leading to an asyncio error message when attempting to use the engine under certain circumstances. Fixes: #6409 Change-Id: I8119c56b44a7bd70a650c0ea676892d4d7814a8b
* accommodate HasEntityNamespace in context.all_selected_columnsMike Bayer2021-04-291-0/+21
| | | | | | | | | | Fixed regression in hybrid_property where a hybrid against a SQL function would generate an ``AttributeError`` when attempting to generate an entry for the ``.c`` collection of a subquery in some cases; among other things this would impact its use in cases like that of ``Query.count()``. Fixes: #6401 Change-Id: Icc243c699e9a5c88448076c6427ec389eaa8b8ed
* add optional proxy_class to track w/ proxy_keyMike Bayer2021-04-281-0/+63
| | | | | | | | | | | Fixed regression in ORM where using hybrid property to indicate an expression from a different entity would confuse the column-labeling logic in the ORM and attempt to derive the name of the hybrid from that other class, leading to an attribute error. The owning class of the hybrid attribute is now tracked along with the name. Fixes: #6386 Change-Id: Ica9497ea34fef799d6265de44104c1f3f3b30232
* dont assume ClauseElement in attributes, coercionsMike Bayer2021-04-231-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed two distinct issues, each of which would come into play under certain circumstances, most likely however one which is a common mis-configuration in :class:`_hybrid.hybrid_property`, where the "expression" implementation would return a non :class:`_sql.ClauseElement` such as a boolean value. For both issues, 1.3's behavior was to silently ignore the mis-configuration and ultimately attempt to interpret the value as a SQL expression, which would lead to an incorrect query. * Fixed issue regarding interaction of the attribute system with hybrid_property, where if the ``__clause_element__()`` method of the attribute returned a non-:class:`_sql.ClauseElement` object, an internal ``AttributeError`` would lead the attribute to return the ``expression`` function on the hybrid_property itself, as the attribute error was against the name ``.expression`` which would invoke the ``__getattr__()`` method as a fallback. This now raises explicitly. In 1.3 the non-:class:`_sql.ClauseElement` was returned directly. * Fixed issue in SQL argument coercions system where passing the wrong kind of object to methods that expect column expressions would fail if the object were altogether not a SQLAlchemy object, such as a Python function, in cases where the object were not just coerced into a bound value. Again 1.3 did not have a comprehensive argument coercion system so this case would also pass silently. Fixes: #6350 Change-Id: I5bba0a6b27f45e5f8ebadfd6d511fa773388ef7c
* Re-infer statements that got more specific on subsequent passMike Bayer2021-04-204-1/+152
| | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where mypy plugin would not correctly interpret an explicit :class:`_orm.Mapped` annotation in conjunction with a :func:`_orm.relationship` that refers to a class by string name; the correct annotation would be downgraded to a less specific one leading to typing errors. The thing figured out here is that after we've already scanned a class in the semanal stage and created DeclClassApplied, when we are called again with that same DeclClassApplied, for this specific kind of case we actually now have *better* types than we did before, where the left side that looked like List?[Address?] now seems to say builtins.list[official.module.Address] - so let's take the right side expression again, this time embedded in our Mapped._empty_constructor() expression, and run the infer all over again just like mypy would. Just not setting the "wrong" type here fixed the test cases but by re-applying the whole infer we get the correct Mapped[] on the left side too. Fixes: #6255 Change-Id: Iafe7254374f685a8458c7a1db82aafc2ed6d0232
* Merge "Fixed ``instrument_declarative`` registry call."mike bayer2021-04-171-0/+25
|\
| * Fixed ``instrument_declarative`` registry call.Federico Caselli2021-04-171-0/+25
| | | | | | | | | | | | | | | | Fixed :func:`_declarative.instrument_declarative` that called a non existing registry method. Fixes: #6291 Change-Id: I6fc8db84f72240cc82e7f6f3a784c424f5ccfc96