summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
Commit message (Collapse)AuthorAgeFilesLines
...
* | Merge "Type annotations for sqlalchemy.orm.mapped_collection" into mainmike bayer2023-01-241-39/+97
|\ \
| * | Type annotations for sqlalchemy.orm.mapped_collectionMaksim Latysh2023-01-241-39/+97
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- Provide a general summary of your proposed changes in the Title field above --> ### Description <!-- Describe your changes in detail --> An attempt to annotate lib/sqlalchemy/orm/mapped_collection.py with type hints (issue https://github.com/sqlalchemy/sqlalchemy/issues/6810) ### 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. - [ ] 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: #9140 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9140 Pull-request-sha: facb4717134943dd651905f7c72618eb66a9eca5 Change-Id: I0fb80e2ea7ed2247c494487fb6c8d72efb4e9802
* | Merge "fix stringify for CreateSchema" into mainmike bayer2023-01-242-0/+4
|\ \
| * | fix stringify for CreateSchemaMike Bayer2023-01-242-0/+4
| |/ | | | | | | | | | | | | | | Fixed stringify for a the :class:`.CreateSchema` DDL construct, which would fail with an ``AttributeError`` when stringified without a dialect. Fixes: #7664 Change-Id: Ifc1769604bc5219c060f5112f7bdea0f780f1a1c
* | reflect Oracle ROWIDMike Bayer2023-01-241-0/+1
|/ | | | | | | | Added :class:`_oracle.ROWID` to reflected types as this type may be used in a "CREATE TABLE" statement. Fixes: #5047 Change-Id: I818dcf68ed81419d0fd5df5e2d51d6fa0f1be7fc
* Merge "generate stubs for func known functions" into mainmike bayer2023-01-231-0/+149
|\
| * generate stubs for func known functionsMike Bayer2023-01-231-0/+149
| | | | | | | | | | | | | | | | | | | | Added typing for the built-in generic functions that are available from the :data:`_sql.func` namespace, which accept a particular set of arguments and return a particular type, such as for :class:`_sql.count`, :class:`_sql.current_timestamp`, etc. Fixes: #9129 Change-Id: I1a2e0dcca3048c77e84dc786843a7df05c457dfa
* | Merge "Result.__enter__ annotation" into mainmike bayer2023-01-231-1/+1
|\ \
| * | Result.__enter__ annotationMartin Baláž2023-01-231-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed typing issue where the object type when using :class:`_engine.Result` as a context manager were not preserved, indicating :class:`_engine.Result` in all cases rather than the specific :class:`_engine.Result` sub-type. Pull request courtesy Martin Baláž. Fixes: #9136 Closes: #9135 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9135 Pull-request-sha: 97a9829db59db359fbb400ec0d913bdf8954f00a Change-Id: I60a7f89ba39bf0f9fc5e6e7bf09f642167fe476f
* | Run bracket interpretation for reflectionShan2023-01-231-3/+1
|/ | | | | | | | | | | | | | | | | | | | | Fixed bug where a schema name given with brackets, but no dots inside the name, for parameters such as :paramref:`_schema.Table.schema` would not be interpreted within the context of the SQL Server dialect's documented behavior of interpreting explicit brackets as token delimiters, first added in 1.2 for #2626, when referring to the schema name in reflection operations. The original assumption for #2626's behavior was that the special interpretation of brackets was only significant if dots were present, however in practice, the brackets are not included as part of the identifier name for all SQL rendering operations since these are not valid characters within regular or delimited identifiers. Pull request courtesy Shan. Fixes: #9133 Closes: #9134 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9134 Pull-request-sha: 5dac87c82cd3063dd8e50f0075c7c00330be6439 Change-Id: I7a507bc38d75a04ffcb7e920298775baae22c6d1
* clarify __table__, local_tableMike Bayer2023-01-202-11/+19
| | | | | | | | These are typed as FromClause, make sure this is stated up front indicating Table as a subset of possible object types. Change-Id: I15961a69d3655600249e3cfe6c4b3372f97d4485 References: #9130
* Merge "typing updates" into mainmike bayer2023-01-204-39/+86
|\
| * typing updatesMike Bayer2023-01-204-39/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The :meth:`_sql.ColumnOperators.in_` and :meth:`_sql.ColumnOperators.not_in_` are typed to include ``Iterable[Any]`` rather than ``Sequence[Any]`` for more flexibility in argument type. The :func:`_sql.or_` and :func:`_sql.and_` from a typing perspective require the first argument to be present, however these functions still accept zero arguments which will emit a deprecation warning at runtime. Typing is also added to support sending the fixed literal ``False`` for :func:`_sql.or_` and ``True`` for :func:`_sql.and_` as the first argument only, however the documentation now indicates sending the :func:`_sql.false` and :func:`_sql.true` constructs in these cases as a more explicit approach. Fixed typing issue where iterating over a :class:`_orm.Query` object was not correctly typed. Fixes: #9122 Fixes: #9123 Fixes: #9125 Change-Id: I500e3e1b826717b3dd49afa1e682c3c8279c9226
* | implement basic typing for lambda elementsMike Bayer2023-01-192-34/+76
|/ | | | | | | | | | | | | | | | | These weren't working at all, so fixed things up and added a test suite. Keeping things very basic with Any returns etc. as having more specific return types starts making it too cumbersome to write end-user code. Corrected the type passed for "lambda statements" so that a plain lambda is accepted by mypy, pyright, others without any errors about argument types. Additionally implemented typing for more of the public API for lambda statements and ensured :class:`.StatementLambdaElement` is part of the :class:`.Executable` hierarchy so it's typed as accepted by :meth:`_engine.Connection.execute`. Fixes: #9120 Change-Id: Ia7fa34e5b6e43fba02c8f94ccc256f3a68a1f445
* Version 2.0.0rc4 placeholderMike Bayer2023-01-181-1/+1
|
* Merge "refactor code generation tools , include --check command" into mainmike bayer2023-01-183-44/+210
|\
| * refactor code generation tools , include --check commandMike Bayer2023-01-183-44/+210
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in particular it looks like CI was not picking up on the "git diff" oriented commands, which were failing to run due to pathing issues. As we were setting cwd for black/zimports relative to sqlalchemy library, and tox installs it in the venv, black/zimports would fail to run from tox, and since these are subprocess.run we didn't pick up the failure. This overall locks down how zimports/black are run so that we are definitely from the source root, by using the location of tools/ to determine the root. Fixes: #8892 Change-Id: I7c54b747edd5a80e0c699b8456febf66d8b62375
* | Remove redundant 1.x reference (#9115)Sam Bull2023-01-181-4/+0
| |
* | mypy plugin fixesMike Bayer2023-01-182-8/+19
|/ | | | | | | | | | | | | | | | | | | Adjustments made to the mypy plugin to accommodate for some potential changes being made for issue #236 sqlalchemy2-stubs when using SQLAlchemy 1.4. These changes are being kept in sync within SQLAlchemy 2.0. The changes are also backwards compatible with older versions of sqlalchemy2-stubs. Fixed crash in mypy plugin which could occur on both 1.4 and 2.0 versions if a decorator for the :func:`_orm.registry.mapped` decorator were used that was referenced in an expression with more than two components (e.g. ``@Backend.mapper_registry.mapped``). This scenario is now ignored; when using the plugin, the decorator expression needs to be two components (i.e. ``@reg.mapped``). References: https://github.com/sqlalchemy/sqlalchemy2-stubs/issues/236 Fixes: #9102 Change-Id: Ieb1bf7bf8184645bcd43253e57f1c267b2640537
* pass driver_connection to TypeInfo.fetch()Mike Bayer2023-01-171-2/+2
| | | | | | | | | Fixed regression where psycopg3 changed an API call as of version 3.1.8 to expect a specific object type that was previously not enforced, breaking connectivity for the psycopg3 dialect. Fixes: #9106 Change-Id: Ibb42f84b1086f30173aeb6e1f3256c56d129fe6e
* Merge "dont assume copy_with() on builtins list, dict, etc; improve error ↵mike bayer2023-01-172-3/+30
|\ | | | | | | msg." into main
| * dont assume copy_with() on builtins list, dict, etc; improve error msg.Mike Bayer2023-01-162-3/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed issue where using an ``Annotated`` type in the ``type_annotation_map`` which itself contained a plain container type (e.g. ``list``, ``dict``) generic type as the target type would produce an internal error where the ORM were trying to interpret the ``Annotated`` instance. Added an error message when a :func:`_orm.relationship` is mapped against an abstract container type, such as ``Mapped[Sequence[B]]``, without providing the :paramref:`_orm.relationship.container_class` parameter which is necessary when the type is abstract. Previously the the abstract container would attempt to be instantiated and fail. Fixes: #9099 Fixes: #9100 Change-Id: I18aa6abd5451c5ac75a9caed8441ff0cd8f44589
* | apply changelog note for change of column loader optionsMike Bayer2023-01-161-2/+2
|/ | | | | | Change-Id: Ib9a69e20420e1fda755f4533c5f90bc08ba11b48 References: #8879 References: #9101
* super-fine pass through the metadata tutorialMike Bayer2023-01-151-2/+122
| | | | | | | | | | try to keep the wordiness down here, using sidebars and topics for non-essential information. Sphinx seems to read out attrs from under TYPE_CHECKING sections now so link out the attrs in DeclarativeBase w/ docstrings, not sure why we didn't think of this earlier. looks great Change-Id: Ib2e07e3606185998561c2d77b2564fd3eddb4d75
* apply pep-612 to hybrid_method; accept SQLCoreOperationsMike Bayer2023-01-142-10/+25
| | | | | | | | | | | | Fixes to the annotations within the ``sqlalchemy.ext.hybrid`` extension for more effective typing of user-defined methods. The typing now uses :pep:`612` features, now supported by recent versions of Mypy, to maintain argument signatures for :class:`.hybrid_method`. Return values for hybrid methods are accepted as SQL expressions in contexts such as :meth:`_sql.Select.where` while still supporting SQL methods. Fixes: #9096 Change-Id: Id4e3a38ec50e415220dfc5f022281b11bb262469
* implement polymorphic_abstract=True featureMike Bayer2023-01-142-20/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a new parameter to :class:`_orm.Mapper` called :paramref:`_orm.Mapper.polymorphic_abstract`. The purpose of this directive is so that the ORM will not consider the class to be instantiated or loaded directly, only subclasses. The actual effect is that the :class:`_orm.Mapper` will prevent direct instantiation of instances of the class and will expect that the class does not have a distinct polymorphic identity configured. In practice, the class that is mapped with :paramref:`_orm.Mapper.polymorphic_abstract` can be used as the target of a :func:`_orm.relationship` as well as be used in queries; subclasses must of course include polymorphic identities in their mappings. The new parameter is automatically applied to classes that subclass the :class:`.AbstractConcreteBase` class, as this class is not intended to be instantiated. Additionally, updated some areas of the single table inheritance documentation to include mapped_column(nullable=False) for all subclass-only columns; the mappings as given didn't work as the columns were no longer nullable using Annotated Declarative Table style. Fixes: #9060 Change-Id: Ief0278e3945a33a6ff38ac14d39c38ce24910d7f
* Merge "Type annotations for sqlalchemy.sql.selectable" into mainmike bayer2023-01-137-108/+224
|\
| * Type annotations for sqlalchemy.sql.selectableDzmitar2023-01-137-108/+224
| | | | | | | | | | | | | | | | | | Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Closes: #9028 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9028 Pull-request-sha: e2f8ddeac0b08feaad917285e988acf1e9465a26 Change-Id: I5caad31bfeeed2d224657a55f067ba1d86b8733f
* | Fixes related to improved sql formattingFederico Caselli2023-01-128-79/+191
|/ | | | | | Follow up of I07b72e6620bb64e329d6b641afa27631e91c4f16 Change-Id: I1f61974bf9cdc3da5317e546d4f9b649c2029e4d
* Merge "replace @decorated_property decorator" into mainmike bayer2023-01-127-57/+16
|\
| * replace @decorated_property decoratorMike Bayer2023-01-127-57/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | This decorator is no longer necessary as of Mypy 0.981 [1]. In current mypy versions, we require direct use of `@property` for return types of these methods to be recognized [1] https://github.com/python/mypy/issues/1362 Change-Id: Ibc36083dec854c5f9140a9b621e9bf9d5bb4fb61
* | Merge "Support local timespamp support on Oracle" into mainmike bayer2023-01-122-2/+35
|\ \ | |/ |/|
| * Support local timespamp support on OracleFederico Caselli2023-01-122-2/+35
| | | | | | | | | | | | | | | | Added support for the Oracle SQL type ``TIMESTAMP WITH LOCAL TIME ZONE``, using a newly added Oracle-specific :class:`_oracle.TIMESTAMP` datatype. Fixes: #9086 Change-Id: Ib14119503a8aaf20e1aa4e36be80ccca37383e90
* | Merge "Improve sql formatting" into mainmike bayer2023-01-1210-76/+74
|\ \
| * | Improve sql formattingFederico Caselli2023-01-1110-76/+74
| | | | | | | | | | | | | | | | | | change {opensql} to {printsql} in prints, add missing markers Change-Id: I07b72e6620bb64e329d6b641afa27631e91c4f16
* | | Move docs in mysql dbapiFederico Caselli2023-01-112-14/+13
| |/ |/| | | | | | | Fixes: #9084 Change-Id: I5e174c318a20b7fcb5ea7c771293c5102e761ed7
* | fix ORM support for column-named bindparam() in crud .values()Mike Bayer2023-01-111-3/+7
|/ | | | | | | | | | | | | | | | | | | Fixed bug / regression where using :func:`.bindparam()` with the same name as a column in the :meth:`.Update.values` method of :class:`.Update`, as well as the :meth:`.Insert.values` method of :class:`.Insert` in 2.0 only, would in some cases silently fail to honor the SQL expression in which the parameter were presented, replacing the expression with a new parameter of the same name and discarding any other elements of the SQL expression, such as SQL functions, etc. The specific case would be statements that were constructed against ORM entities rather than plain :class:`.Table` instances, but would occur if the statement were invoked with a :class:`.Session` or a :class:`.Connection`. :class:`.Update` part of the issue was present in both 2.0 and 1.4 and is backported to 1.4. Fixes: #9075 Change-Id: Ie954bc1f492ec6a566163588182ef4910c7ee452
* Version 2.0.0rc3 placeholderMike Bayer2023-01-091-1/+1
|
* Merge "accept TableClause through mapped selectable chain" into mainmike bayer2023-01-093-21/+19
|\
| * accept TableClause through mapped selectable chainMike Bayer2023-01-093-21/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | type annotation somehow decided that TableClause doesn't have primary key fields which is not the case at all. In particular the "views" recipe relies on TableClause so adding a restriction like this does not make any sense. It seems the issue was to open this up for typing, by allowing TableClause out as far as ddl.sort_tables() typing is passing for now. Support it out in get_bind() etc. Fixes: #9071 Change-Id: If0e22e0e7df7bee0ff4b295b0ffacfbc6b7a0142
* | Merge "warn and skip for FKs that refer to invisible cols for Oracle" into mainFederico Caselli2023-01-093-21/+39
|\ \
| * | warn and skip for FKs that refer to invisible cols for OracleMike Bayer2023-01-093-21/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Supported use case for foreign key constraints where the local column is marked as "invisible". The errors normally generated when a :class:`.ForeignKeyConstraint` is created that check for the target column are disabled when reflecting, and the constraint is skipped with a warning in the same way which already occurs for an :class:`.Index` with a similar issue. tests are added for indexes, unique constraints, and primary key constraints, which were already working; indexes and uniques warn, primary keys don't which we would assume is because we never see those PK columns in the first place. Constraints now raise an informative ConstraintColumnNotFoundError in the general case for strings in the "pending colargs" collection not being resolvable. Fixes: #9059 Change-Id: I400cf0bff6abba0e0c75f38b07617be1a8ec3453
* | | remove misleading line in post_updateMike Bayer2023-01-091-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | this UPDATE refers to the unit of work's need to consider this additional UPDATE as a dependency and not an actual UPDATE statement. Change-Id: I2a520af21ebf96b45c431efa898d4e7683a5bc2d References: #9066 References: #1063
* | | Merge "Implement missing `#-`, `@?` and `@@` Postgres' JSONB operators." ↵mike bayer2023-01-091-1/+64
|\ \ \ | | | | | | | | | | | | into main
| * | | Implement missing `#-`, `@?` and `@@` Postgres' JSONB operators.Guilherme Martins Crocetti2023-01-051-1/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #7147. Closes: #9038 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9038 Pull-request-sha: 8647aaf2d9f48c55c152673828deb8ed54966a11 Change-Id: Id2f611ed8080a2837c70d2ea4b41abc46d2bb026
* | | | Use field_specifiers instead of deprecated field_descriptorsFederico Caselli2023-01-081-2/+2
| |_|/ |/| | | | | | | | | | | | | | | | | | | | The Data Class Transforms argument ``field_descriptors`` was renamed to ``field_specifiers`` in the accepted version of PEP 681. Fixes: #9067 Change-Id: Ic13ea93c157325c3b60e65f328a364da68ea1c46
* | | Merge "revert MySQL to use DESCRIBE for has_table()" into mainmike bayer2023-01-053-29/+47
|\ \ \ | |_|/ |/| |
| * | revert MySQL to use DESCRIBE for has_table()Mike Bayer2023-01-053-29/+47
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Restored the behavior of :meth:`.Inspector.has_table` to report on temporary tables for MySQL / MariaDB. This is currently the behavior for all other included dialects, but was removed for MySQL in 1.4 due to no longer using the DESCRIBE command; there was no documented support for temp tables being reported by the :meth:`.Inspector.has_table` method in this version or on any previous version, so the previous behavior was undefined. As SQLAlchemy 2.0 has added formal support for temp table status via :meth:`.Inspector.has_table`, the MySQL /MariaDB dialect has been reverted to use the "DESCRIBE" statement as it did in the SQLAlchemy 1.3 series and previously, and test support is added to include MySQL / MariaDB for this behavior. The previous issues with ROLLBACK being emitted which 1.4 sought to improve upon don't apply in SQLAlchemy 2.0 due to simplifications in how :class:`.Connection` handles transactions. DESCRIBE is necessary as MariaDB in particular has no consistently available public information schema of any kind in order to report on temp tables other than DESCRIBE/SHOW COLUMNS, which rely on throwing an error in order to report no results. Fixes: #9058 Change-Id: Ic511bd5989ec17beb37b7cddd913732b626af0e6
* | Merge "include parsed col length field as integer from mysql index ↵mike bayer2023-01-052-3/+16
|\ \ | | | | | | | | | reflection" into main
| * | include parsed col length field as integer from mysql index reflectionMike Bayer2023-01-042-3/+16
| |/ | | | | | | | | | | | | | | Added support to MySQL index reflection to correctly reflect the ``mysql_length`` dictionary, which previously was being ignored. Fixes: #9047 Change-Id: I0a5e27123be68741e12af4464a0fa305052ec36e