]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
2 years agocollect annotation earlier for mapped_column present
Mike Bayer [Thu, 20 Oct 2022 16:05:33 +0000 (12:05 -0400)] 
collect annotation earlier for mapped_column present

Fixed issue with new dataclass mapping feature where arguments passed to
the dataclasses API could sometimes be mis-ordered when dealing with mixins
that override :func:`_orm.mapped_column` declarations, leading to
initializer problems.

the change made here is specific to the test case given which regards
mapped_column() most specifically.   cases that involve relationship()
etc. are not tested here, however mapped_column() is the only attribute
that's implicit without an instance given on the right side, and is also
most common for mixins.   not clear if there are more issues in this
area, however it appears that we need only adjust the order in which we
accommodate grabbing the annotations in order to affect how dataclasses
sees the class; that is, we have control over ``__annotations__`` here
so dont have to worry about ``cls.__dict__``.

Fixes: #8688
Change-Id: I808c86f23d73aa47cd910ae01c3e07093d469fdc

2 years agoMerge "Improve typing of DeclarativeBase" into main
mike bayer [Thu, 20 Oct 2022 13:20:34 +0000 (13:20 +0000)] 
Merge "Improve typing of DeclarativeBase" into main

2 years agoImprove typing of DeclarativeBase
Federico Caselli [Tue, 18 Oct 2022 19:08:48 +0000 (21:08 +0200)] 
Improve typing of DeclarativeBase

Also allow mapped columns inside indexes, unique cosntraints, primary key constriant

Fixes: #8645
Change-Id: If37ab85ead0fbd1125cd6329c2f01a031777b081

2 years agomore many-to-one typing
Mike Bayer [Wed, 19 Oct 2022 13:41:44 +0000 (09:41 -0400)] 
more many-to-one typing

since we are typing centric, note this configuration
as we have just supported in #8668.

Note also I am just taking "backref" out of the basic
version of the docs here totally, this doc is already
a lot to read / take in without making it even more
confusing; backref still has an entirely dedicated
docs page which can have all the additional behaviors
of backref() described.

Additionally, get other "optional" forms to work including
``cls | None`` and ``Union[cls, None]``.

Fixes: #8668
Change-Id: I2b026f496a1710ddebfb4aa6cf8459b4892cbc54

2 years agoMerge "de-optionalize union types to support Optional for m2o" into main
mike bayer [Wed, 19 Oct 2022 13:33:55 +0000 (13:33 +0000)] 
Merge "de-optionalize union types to support Optional for m2o" into main

2 years agoMerge "call super().__init_subclass__(); support GenericAlias" into main
mike bayer [Wed, 19 Oct 2022 13:33:34 +0000 (13:33 +0000)] 
Merge "call super().__init_subclass__(); support GenericAlias" into main

2 years agorename tables to _table for basic relationships
Mike Bayer [Wed, 19 Oct 2022 13:17:03 +0000 (09:17 -0400)] 
rename tables to _table for basic relationships

the names "parent" / "child" are confusing for new users
in that they are used for table names as well as
"back_populates='parent'", use a disambiguated name.

In this change, there's now overlap between the
variable named "association_table" and the table name
"association_table".  not sure of a better naming system.

Change-Id: Ic036c8072caf6e9e5fbd1178986353c00b91f43d
References: https://github.com/sqlalchemy/sqlalchemy/discussions/8675#discussioncomment-3915204

2 years agode-optionalize union types to support Optional for m2o
Mike Bayer [Wed, 19 Oct 2022 01:01:05 +0000 (21:01 -0400)] 
de-optionalize union types to support Optional for m2o

Fixed bug in new ORM typed declarative mappings where we did not include
the ability to use ``Optional[]`` in the type annotation for a many-to-one
relationship, even though this is common.

Fixes: #8668
Change-Id: Idaf0846e49cc12095394b99ad6fe678735cf9242

2 years agocall super().__init_subclass__(); support GenericAlias
Mike Bayer [Tue, 18 Oct 2022 17:25:06 +0000 (13:25 -0400)] 
call super().__init_subclass__(); support GenericAlias

Improved the :class:`.DeclarativeBase` class so that when combined with
other mixins like :class:`.MappedAsDataclass`, the order of the classes may
be in either order.

Added support for mapped classes that are also ``Generic`` subclasses,
to be specified as a ``GenericAlias`` object (e.g. ``MyClass[str]``)
within statements and calls to :func:`_sa.inspect`.

Fixes: #8665
Change-Id: I03063a28b0438a44b9e028fd9d45e8ce08bd18c4

2 years agoMerge "further qualify pyodbc setinputsizes types for long stirngs" into main
mike bayer [Wed, 19 Oct 2022 00:18:17 +0000 (00:18 +0000)] 
Merge "further qualify pyodbc setinputsizes types for long stirngs" into main

2 years agofurther qualify pyodbc setinputsizes types for long stirngs
Mike Bayer [Tue, 18 Oct 2022 13:44:37 +0000 (09:44 -0400)] 
further qualify pyodbc setinputsizes types for long stirngs

Fixed regression caused by SQL Server pyodbc change :ticket:`8177` where we
now use ``setinputsizes()`` by default; for VARCHAR, this fails if the
character size is greater than 4000 (or 2000, depending on data) characters
as the incoming datatype is NVARCHAR, which has a limit of 4000 characters,
despite the fact that VARCHAR can handle unlimited characters. Additional
pyodbc-specific typing information is now passed to ``setinputsizes()``
when the datatype's size is > 2000 characters. The change is also applied
to the :class:`.JSON` type which was also impacted by this issue for large
JSON serializations.

Fixes: #8661
Change-Id: I07fa873e95dbd2c94f3d286e93e8b3229c3a9807

2 years agoImprove proxy methods with the changes from the abandoned
Federico Caselli [Tue, 18 Oct 2022 17:57:19 +0000 (19:57 +0200)] 
Improve proxy methods with the changes from the abandoned
I5c7f172e5224fa08d0675160ac919d0b045a26eb

Change-Id: Ieb7971297f959fd635a4627bd93154e28ef0ef2b

2 years agoRevert automatic set of sequence start to 1
Federico Caselli [Sat, 24 Sep 2022 13:50:26 +0000 (15:50 +0200)] 
Revert automatic set of sequence start to 1

The :class:`.Sequence` construct restores itself to the DDL behavior it
had prior to the 1.4 series, where creating a :class:`.Sequence` with
no additional arguments will emit a simple ``CREATE SEQUENCE`` instruction
**without** any additional parameters for "start value".   For most backends,
this is how things worked previously in any case; **however**, for
MS SQL Server, the default value on this database is
``-2**63``; to prevent this generally impractical default
from taking effect on SQL Server, the :paramref:`.Sequence.start` parameter
should be provided.   As usage of :class:`.Sequence` is unusual
for SQL Server which for many years has standardized on ``IDENTITY``,
it is hoped that this change has minimal impact.

Fixes: #7211
Change-Id: I1207ea10c8cb1528a1519a0fb3581d9621c27b31

2 years agoupdate SEQUENCE docs ahead of default change
Mike Bayer [Mon, 17 Oct 2022 19:09:01 +0000 (15:09 -0400)] 
update SEQUENCE docs ahead of default change

for backport to 1.4 as well, remove references to
Firebird, and also revert "associate Sequence with MetaData"
step as this is not needed usually, just note that schema
is not shared.  encourage users to use IDENTITY instead.

Change-Id: I5d25357042127c9cd1274c9de7abb44a525b0195

2 years agosimplify unmapped col eval fallback
Mike Bayer [Mon, 17 Oct 2022 15:53:07 +0000 (11:53 -0400)] 
simplify unmapped col eval fallback

Removed the warning that emits when using ORM-enabled update/delete
regarding evaluation of columns by name, first added in :ticket:`4073`;
this warning actually covers up a scenario that otherwise could populate
the wrong Python value for an ORM mapped attribute depending on what the
actual column is, so this deprecated case is removed. In 2.0, ORM enabled
update/delete uses "auto" for "synchronize_session", which should do the
right thing automatically for any given UPDATE expression.

Fixes: #8656
Change-Id: Idb8b4a86d3caed89f69cde1607886face103cf6a

2 years agofix imports in asyncio example
Mike Bayer [Mon, 17 Oct 2022 13:00:20 +0000 (09:00 -0400)] 
fix imports in asyncio example

Change-Id: I1f746f9dafac35dc9c9def8ee16a6ee7eacdfcfe

2 years agoMerge "repair type qualify in _ServerDefaultType; other pyright tweaks" into main
mike bayer [Mon, 17 Oct 2022 12:59:05 +0000 (12:59 +0000)] 
Merge "repair type qualify in _ServerDefaultType; other pyright tweaks" into main

2 years agorepair type qualify in _ServerDefaultType; other pyright tweaks
Mike Bayer [Sun, 16 Oct 2022 22:30:44 +0000 (18:30 -0400)] 
repair type qualify in _ServerDefaultType; other pyright tweaks

as we haven't done full pylance / pyright strict typing internally,
some of the things pyright reports on specifically will leak
out into user code, such as this mapped_column() issue.
So we will have to look more closely at pyright strict
mode going forward for the release.

Fixed typing issue where pylance strict mode would report "partially
unknown" datatype for the :func:`_orm.mapped_column` construct.

Also repaired a trailing comma and pyright complaining about overloads
for orm.composite.

Fixes: #8644
Change-Id: Ia48dc5dbd56bbceeacee4f0daf9810bfdea3bee3

2 years agocherry-pick changelog update for 1.4.43
Mike Bayer [Sun, 16 Oct 2022 14:25:36 +0000 (10:25 -0400)] 
cherry-pick changelog update for 1.4.43

2 years agocherry-pick changelog from 1.4.42
Mike Bayer [Sun, 16 Oct 2022 14:25:36 +0000 (10:25 -0400)] 
cherry-pick changelog from 1.4.42

2 years agoadd python 3.11 to supported versions
Mike Bayer [Sun, 16 Oct 2022 14:09:20 +0000 (10:09 -0400)] 
add python 3.11 to supported versions

Change-Id: Ibf699297b12c1c72c570db380282e97adfdef2b9

2 years agoaccommodate arbitrary embedded params in insertmanyvalues
Mike Bayer [Sat, 15 Oct 2022 19:20:21 +0000 (15:20 -0400)] 
accommodate arbitrary embedded params in insertmanyvalues

Fixed bug in new "insertmanyvalues" feature where INSERT that included a
subquery with :func:`_sql.bindparam` inside of it would fail to render
correctly in "insertmanyvalues" format. This affected psycopg2 most
directly as "insertmanyvalues" is used unconditionally with this driver.

Fixes: #8639
Change-Id: I67903fa86afe208899d4f23f940e0727d1be2ce3

2 years agodisable isort in pyproject.toml
Mike Bayer [Sat, 15 Oct 2022 15:12:25 +0000 (11:12 -0400)] 
disable isort in pyproject.toml

disable isort, for IDEs that just default isort to be turned on, e.g. vscode.
we use flake8-import-order for import sorting, using zimports to actually
reformat code.  isort is nicer in many ways but doesn't have our
"import *" fixer and also is not 100% compatible with flake8-import-order.

Change-Id: I8e53d475cdc1d6178e2c9276d2b21d47be207ede

2 years agofix instances of objects as instances of classes (#8627)
Muhammad Abdur Rakib [Fri, 14 Oct 2022 17:53:49 +0000 (23:53 +0600)] 
fix instances of objects as instances of classes (#8627)

document mentions `creating instances of "User" and "Address" objects` which is a mistake as we create instances or objects from classes.

2 years agoBump pypa/cibuildwheel from 2.10.2 to 2.11.1 (#8630)
dependabot[bot] [Fri, 14 Oct 2022 17:47:26 +0000 (19:47 +0200)] 
Bump pypa/cibuildwheel from 2.10.2 to 2.11.1 (#8630)

Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.10.2 to 2.11.1.
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.10.2...v2.11.1)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 years agocorrect python compat statement
Mike Bayer [Fri, 14 Oct 2022 15:33:54 +0000 (11:33 -0400)] 
correct python compat statement

2.0 uses 3.7 at a minimum, update verbiage here.

Change-Id: I076e205bbfc9b502f1ac382f6292c290c3fc8c1b

2 years agonarrow formatting in table, turn format off
Mike Bayer [Fri, 14 Oct 2022 13:17:09 +0000 (09:17 -0400)] 
narrow formatting in table, turn format off

Change-Id: I0824495e0582657ffb63eaa2466021f56005c81c
References: https://github.com/sqlalchemy/sqlalchemy/discussions/8157#discussioncomment-3878806

2 years agofix declarative styles examples re: imports
Mike Bayer [Fri, 14 Oct 2022 12:41:03 +0000 (08:41 -0400)] 
fix declarative styles examples re: imports

many missing imports and mis-imports, also use
list[] for typing.

Change-Id: Idd9140a89eb421c4b80503639a582b96ba66c601
References: #8634

2 years agofix comment
Mike Bayer [Thu, 13 Oct 2022 15:59:02 +0000 (11:59 -0400)] 
fix comment

Change-Id: I9aaaf1df05a4f54fa0907155160022815280d12e

2 years agoVersion 2.0.0b2 placeholder
Mike Bayer [Thu, 13 Oct 2022 15:32:52 +0000 (11:32 -0400)] 
Version 2.0.0b2 placeholder

2 years ago- 2.0.0b1 rel_2_0_0b1
Mike Bayer [Thu, 13 Oct 2022 15:25:31 +0000 (11:25 -0400)] 
- 2.0.0b1

2 years agofurther 2.0 modernizations
Mike Bayer [Thu, 13 Oct 2022 14:13:01 +0000 (10:13 -0400)] 
further 2.0 modernizations

biggest change here is the old tutorials were removed from the
TOC and some additional links to them have been corrected.

Change-Id: I79b878a946422eac24ed2449b440fc5d556576c4

2 years agofixes for doc builds
Mike Bayer [Thu, 13 Oct 2022 13:12:04 +0000 (09:12 -0400)] 
fixes for doc builds

* requirements needs typing_extensions
* update all "future=True" references to be appropriate to 2.0

Change-Id: I2eeb0ae65afdb587f21aeb0020f1d8a292f67c21

2 years agorework test query to work on MSSQL
Mike Bayer [Thu, 13 Oct 2022 12:47:37 +0000 (08:47 -0400)] 
rework test query to work on MSSQL

Change-Id: I14ea04085703736daf78fe0cf307925c192c5e0e

2 years agoMerge "implement autobegin=False option" into main
mike bayer [Wed, 12 Oct 2022 20:06:34 +0000 (20:06 +0000)] 
Merge "implement autobegin=False option" into main

2 years agoimplement autobegin=False option
Mike Bayer [Tue, 11 Oct 2022 21:01:43 +0000 (17:01 -0400)] 
implement autobegin=False option

Added new parameter :paramref:`_orm.Session.autobegin`, which when set to
``False`` will prevent the :class:`_orm.Session` from beginning a
transaction implicitly. The :meth:`_orm.Session.begin` method must be
called explicitly first in order to proceed with operations, otherwise an
error is raised whenever any operation would otherwise have begun
automatically. This option can be used to create a "safe"
:class:`_orm.Session` that won't implicitly start new transactions.

As part of this change, also added a new status variable
:class:`_orm.SessionTransaction.origin` which may be useful for event
handling code to be aware of the origin of a particular
:class:`_orm.SessionTransaction`.

Fixes: #6928
Change-Id: I246f895c4a475bff352216e5bc74b6a25e6a4ae7

2 years agoMerge "warn for no polymorphic identity w/ poly hierarchy" into main
mike bayer [Tue, 11 Oct 2022 22:18:48 +0000 (22:18 +0000)] 
Merge "warn for no polymorphic identity w/ poly hierarchy" into main

2 years agoMerge "enable check same thread for aiosqlite" into main
mike bayer [Tue, 11 Oct 2022 22:17:44 +0000 (22:17 +0000)] 
Merge "enable check same thread for aiosqlite" into main

2 years agoupdate executemany for new features
Mike Bayer [Tue, 11 Oct 2022 19:29:15 +0000 (15:29 -0400)] 
update executemany for new features

also fixes issue in format_docs_code which didn't work with
pre-commit for more than one file.  will backport

Fixes: #8597
Change-Id: I21b2625514987b1cd90f7c00f06e72e57e257390

2 years agowarn for no polymorphic identity w/ poly hierarchy
Mike Bayer [Mon, 10 Oct 2022 18:03:04 +0000 (14:03 -0400)] 
warn for no polymorphic identity w/ poly hierarchy

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

2 years agoMerge "rename MappedCollection and related" into main
mike bayer [Tue, 11 Oct 2022 18:29:50 +0000 (18:29 +0000)] 
Merge "rename MappedCollection and related" into main

2 years agoenable check same thread for aiosqlite
Mike Bayer [Tue, 11 Oct 2022 18:22:40 +0000 (14:22 -0400)] 
enable check same thread for aiosqlite

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

2 years agoMerge "doc edits" into main
mike bayer [Tue, 11 Oct 2022 14:34:28 +0000 (14:34 +0000)] 
Merge "doc edits" into main

2 years agorename MappedCollection and related
Mike Bayer [Fri, 7 Oct 2022 18:03:16 +0000 (14:03 -0400)] 
rename MappedCollection and related

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

2 years agodoc edits
Mike Bayer [Thu, 6 Oct 2022 15:57:06 +0000 (11:57 -0400)] 
doc edits

this is addressing comments still remaining on
I9929daab7797be9515f71c888b28af1209e789ff

removes "asyncio" wording discussed in #7659

Change-Id: I1bab2a6fde330b83ef34602956c2988ee6331b21

2 years agoMerge "Add format docs to pre-commits" into main
mike bayer [Mon, 10 Oct 2022 14:16:07 +0000 (14:16 +0000)] 
Merge "Add format docs to pre-commits" into main

2 years agodont mutate bind_arguments incoming dictionary
Mike Bayer [Fri, 7 Oct 2022 15:25:08 +0000 (11:25 -0400)] 
dont mutate bind_arguments incoming dictionary

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

2 years agoAdd format docs to pre-commits
Federico Caselli [Thu, 6 Oct 2022 20:26:39 +0000 (22:26 +0200)] 
Add format docs to pre-commits

Change-Id: Ia41399155ee0ec1b878aebf18967eabe38f5afd1

2 years agoBump pypa/cibuildwheel from 2.10.1 to 2.10.2 (#8581)
dependabot[bot] [Thu, 6 Oct 2022 19:26:41 +0000 (21:26 +0200)] 
Bump pypa/cibuildwheel from 2.10.1 to 2.10.2 (#8581)

Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.10.1 to 2.10.2.
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.10.1...v2.10.2)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 years agofix execute calls for 2.0
Mike Bayer [Thu, 6 Oct 2022 17:12:31 +0000 (13:12 -0400)] 
fix execute calls for 2.0

Change-Id: Iae802ed365544fb7154adc365776f017156b0108

2 years agoimplement write-only colletions, typing for dynamic
Mike Bayer [Mon, 26 Sep 2022 18:38:44 +0000 (14:38 -0400)] 
implement write-only colletions, typing for dynamic

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

2 years agoreorganize Mapped[] super outside of MapperProperty
Mike Bayer [Thu, 29 Sep 2022 16:56:23 +0000 (12:56 -0400)] 
reorganize Mapped[] super outside of MapperProperty

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

2 years agoMerge "adjust MySQL view reflection for non-standard MySQL variants" into main
mike bayer [Wed, 5 Oct 2022 14:53:42 +0000 (14:53 +0000)] 
Merge "adjust MySQL view reflection for non-standard MySQL variants" into main

2 years agoMake if_exists and if_not_exists flags on ddl statements match compiler
Jesse Bakker [Tue, 6 Sep 2022 20:00:10 +0000 (16:00 -0400)] 
Make if_exists and if_not_exists flags on ddl statements match compiler

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

2 years agoMerge "use black 22.8.0" into main
mike bayer [Mon, 3 Oct 2022 22:27:20 +0000 (22:27 +0000)] 
Merge "use black 22.8.0" into main

2 years agoadjust MySQL view reflection for non-standard MySQL variants
John Bodley [Fri, 30 Sep 2022 01:58:58 +0000 (21:58 -0400)] 
adjust MySQL view reflection for non-standard MySQL variants

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

2 years agouse black 22.8.0
Mike Bayer [Mon, 3 Oct 2022 21:40:08 +0000 (17:40 -0400)] 
use black 22.8.0

nothing happened moving from 22.3 to 22.8.  a full run of pre-commit
found some little things in the generate_proxy_methods script.

Change-Id: Ie6b4235b87bbfcb252759c0afb133ab8d0cf51db

2 years agoRemove all formatting errors
Federico Caselli [Mon, 3 Oct 2022 08:17:29 +0000 (10:17 +0200)] 
Remove all formatting errors

Improve format docs script, replace {sql} with {opensql}

Change-Id: Ie1aaa8f3d8ff8f8e89b7b5149a1876d9f8a211ed

2 years agoclarify precedence docs
Mike Bayer [Mon, 3 Oct 2022 15:40:27 +0000 (11:40 -0400)] 
clarify precedence docs

Change-Id: I748f2736eb6382c8625b3419a82785b48766d8f7
references: #8584

2 years agothe future is here
Mike Bayer [Mon, 3 Oct 2022 01:22:11 +0000 (21:22 -0400)] 
the future is here

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

2 years agodetect {opensql} and {stop} sections
Mike Bayer [Sun, 2 Oct 2022 16:18:23 +0000 (12:18 -0400)] 
detect {opensql} and {stop} sections

this so that I can still have
{opensql} and {stop} sections in non-console python.

this isn't the norm but I would prefer if I dont have to
be 100% strict about it

also maintaining {sql} / {stop} being at the start
of a code line.  this is more prevalent in 1.4.

Change-Id: Iaf748b7ff1120e21f729c2fd794d9b8a33d83170

2 years agoAdd proper code block formatting
Federico Caselli [Sat, 1 Oct 2022 21:49:55 +0000 (23:49 +0200)] 
Add proper code block formatting

Change-Id: I63585eeae0b0bc78109da64520696928dfb3982c

2 years agoImprovements to code formatter
Federico Caselli [Fri, 30 Sep 2022 21:46:42 +0000 (23:46 +0200)] 
Improvements to code formatter

Change-Id: I75cf7143f3ed3bbc09aa8bc18edbce5c8af0f0be

2 years agoadd disable doctest tag for autodoc test suite
Mike Bayer [Sun, 2 Oct 2022 02:24:38 +0000 (22:24 -0400)] 
add disable doctest tag for autodoc test suite

ahead of trying to get everything formatted, some more
flexibility so that we can use doctest for all
python + sql code, while still being able to tell the
test suite to not run doctests on a sample.    All of the
"non-console python with SQL" in the docs is because I was
showing an example that I didn't want tested.

Change-Id: Iae876ae1ffd93c36b096c6c2d6048843ae9698c8

2 years agointerim adjustment to code that's not staying formatted
Mike Bayer [Fri, 30 Sep 2022 21:08:06 +0000 (17:08 -0400)] 
interim adjustment to code that's not staying formatted

@caselit is fixing this but i just need the build
to pass for the moment

Change-Id: I1c39304c5541ac6f09a80fc157f86f1c86421235

2 years agofix "entry points"
Mike Bayer [Fri, 30 Sep 2022 20:58:26 +0000 (16:58 -0400)] 
fix "entry points"

the formatting here wasn't round tripping without manually
adjusting the indentation.  this suggests that "check" mode
is not doing the exact same thing as "write".  maybe
file.write_text() is changing something.

Change-Id: Ic320800eea7d3333b8a76ede85293c2832c619ed

2 years agorun proxy doc generation for updated session methods
Mike Bayer [Fri, 30 Sep 2022 18:53:31 +0000 (14:53 -0400)] 
run proxy doc generation for updated session methods

Change-Id: I0e86d78c2b56e8a1c85d5848b42a9eb4081bacfd

2 years agothis is python code, we can format
Mike Bayer [Fri, 30 Sep 2022 18:53:02 +0000 (14:53 -0400)] 
this is python code, we can format

Change-Id: I01aee8b50afe84b8df6154fa73a4375d746cbc02

2 years agoMerge "Format code in the rst docs file" into main
mike bayer [Fri, 30 Sep 2022 18:43:54 +0000 (18:43 +0000)] 
Merge "Format code in the rst docs file" into main

2 years agoFormat code in the rst docs file
Federico Caselli [Tue, 27 Sep 2022 21:29:57 +0000 (23:29 +0200)] 
Format code in the rst docs file

Added script to format code in the rst documentation using black.
This is also added to the lint tox job to ensure that the code
in the docs is properly formatted.

Change-Id: I799444f22da153484ca5f095d57755762348da40

2 years agoadd autobuild; improve a few session docs
Mike Bayer [Fri, 30 Sep 2022 17:07:04 +0000 (13:07 -0400)] 
add autobuild; improve a few session docs

this is from the writeonly patch, some doc edits became
more general so will backport these to 1.4.

Change-Id: I19231e4bcfa33a0742c8995b6059c9a9488b1a6f

2 years agotypo
Mike Bayer [Thu, 29 Sep 2022 21:40:27 +0000 (17:40 -0400)] 
typo

Change-Id: I88d4632accb641c4b7ee306e8ab54a0f46bc6f37

2 years agorewrite the first section of ORM quickstart
Mike Bayer [Thu, 29 Sep 2022 21:23:47 +0000 (17:23 -0400)] 
rewrite the first section of ORM quickstart

I tried reading what was there and I couldn't even follow it.

This way has pretty straight paragraphs describing each thing
though there's really no way to make this much shorter without
just leaving things out.

Will try to backport the relevant aspects to 1.4.

Change-Id: I65ebec40c9d873bfa9884a556b5ca1300f7a4cc0

2 years agoMerge "Document user-defined functions for sqlite" into main
mike bayer [Thu, 29 Sep 2022 13:09:52 +0000 (13:09 +0000)] 
Merge "Document user-defined functions for sqlite" into main

2 years agocorrect test criteria for mssql
Mike Bayer [Tue, 27 Sep 2022 14:23:28 +0000 (10:23 -0400)] 
correct test criteria for mssql

this test was failing on mssql b.c. mssql
reports false for supports_default_metavalue. however
insertmanyvalues is still used in this case, and the
assert SQL is against the default dialect in any case.

Change-Id: If8301bf4c1ed090dd1440328aba1644b597e58d8

2 years agoadd "index", "unique" to Column.merge() attrs
Mike Bayer [Tue, 27 Sep 2022 02:31:05 +0000 (22:31 -0400)] 
add "index", "unique" to Column.merge() attrs

Fixes: #8578
Change-Id: Ic79c19748d5bb00353d0a97f3a4b4f5eb9fdbb0c

2 years agoadjust for mypy 0.981
Mike Bayer [Mon, 26 Sep 2022 22:05:42 +0000 (18:05 -0400)] 
adjust for mypy 0.981

new release is out today, fix a very small number of new
issues.

Change-Id: I443c78f3384319d56deb2c9309118ffb750bbf41

2 years agoMerge "add typing for sqlalchemy.orm.validates" into main
mike bayer [Mon, 26 Sep 2022 12:57:31 +0000 (12:57 +0000)] 
Merge "add typing for sqlalchemy.orm.validates" into main

2 years agoadjust tests for sqlites w/o returning
Mike Bayer [Mon, 26 Sep 2022 12:54:59 +0000 (08:54 -0400)] 
adjust tests for sqlites w/o returning

the sqlite builds on github actions seem to be very
inconsistent about versions and many don't support
RETURNING.  ensure any tests that depend on RETURNING present
are marked as such.

Change-Id: I7a60a81fa70b90642448cdd58eda33212c3afebc

2 years agoMerge "`aggregate_order_by` now supports cache generation." into main
mike bayer [Mon, 26 Sep 2022 02:33:19 +0000 (02:33 +0000)] 
Merge "`aggregate_order_by` now supports cache generation." into main

2 years agoadd typing for sqlalchemy.orm.validates
Mike Bayer [Mon, 26 Sep 2022 01:40:48 +0000 (21:40 -0400)] 
add typing for sqlalchemy.orm.validates

Fixes: #8577
Change-Id: Iede1c956078960fb866da45f1ac6aa43842516bc

2 years agoMerge "New ORM Query Guide featuring DML support" into main
mike bayer [Mon, 26 Sep 2022 01:18:00 +0000 (01:18 +0000)] 
Merge "New ORM Query Guide featuring DML support" into main

2 years agoMerge "ORM bulk insert via execute" into main
mike bayer [Mon, 26 Sep 2022 01:17:44 +0000 (01:17 +0000)] 
Merge "ORM bulk insert via execute" into main

2 years agoMerge "implement batched INSERT..VALUES () () for executemany" into main
mike bayer [Mon, 26 Sep 2022 01:17:27 +0000 (01:17 +0000)] 
Merge "implement batched INSERT..VALUES () () for executemany" into main

2 years ago`aggregate_order_by` now supports cache generation.
Federico Caselli [Sun, 25 Sep 2022 14:37:15 +0000 (16:37 +0200)] 
`aggregate_order_by` now supports cache generation.

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

2 years agoNew ORM Query Guide featuring DML support
Mike Bayer [Thu, 18 Aug 2022 17:56:50 +0000 (13:56 -0400)] 
New ORM Query Guide featuring DML support

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

2 years agoMerge "warn for local-only column in remote side" into main
mike bayer [Sun, 25 Sep 2022 23:15:46 +0000 (23:15 +0000)] 
Merge "warn for local-only column in remote side" into main

2 years agowarn for local-only column in remote side
Mike Bayer [Sun, 25 Sep 2022 18:56:22 +0000 (14:56 -0400)] 
warn for local-only column in remote side

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

2 years agoUse aggregate order by instead of order by in subquery
Federico Caselli [Sun, 25 Sep 2022 16:20:22 +0000 (18:20 +0200)] 
Use aggregate order by instead of order by in subquery

Fixes: #8561
Change-Id: I2d9f6bd895061bf8fbc66723930716670791d896

2 years agoORM bulk insert via execute
Mike Bayer [Sun, 7 Aug 2022 16:14:19 +0000 (12:14 -0400)] 
ORM bulk insert via execute

* 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

2 years agoadd missing changelog for #8569
Mike Bayer [Sat, 24 Sep 2022 15:16:16 +0000 (11:16 -0400)] 
add missing changelog for #8569

Missed this in 57b400f07951f0ae8651ca383.  have no idea how.

Fixes: #8569
Change-Id: I4cec98d8c963930ef822bfd53d8a60a20be02894

2 years agoimplement batched INSERT..VALUES () () for executemany
Mike Bayer [Mon, 18 Jul 2022 19:08:37 +0000 (15:08 -0400)] 
implement batched INSERT..VALUES () () for executemany

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

2 years agoAdd oracledb to whatsnew list.
Federico Caselli [Sat, 24 Sep 2022 11:05:44 +0000 (13:05 +0200)] 
Add oracledb to whatsnew list.

Change-Id: I8153a6af599a8ce6dfb45bbda13f01801eda3b6e

2 years agoMerge "Tighten password security by removing `URL.__str__`" into main
mike bayer [Sat, 24 Sep 2022 01:02:16 +0000 (01:02 +0000)] 
Merge "Tighten password security by removing `URL.__str__`" into main

2 years agoMerge "remove should_nest behavior for contains_eager()" into main
mike bayer [Sat, 24 Sep 2022 01:00:10 +0000 (01:00 +0000)] 
Merge "remove should_nest behavior for contains_eager()" into main

2 years agoTighten password security by removing `URL.__str__`
Yassen Damyanov [Thu, 22 Sep 2022 16:12:28 +0000 (12:12 -0400)] 
Tighten password security by removing `URL.__str__`

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

2 years agoremove should_nest behavior for contains_eager()
Mike Bayer [Fri, 23 Sep 2022 19:17:57 +0000 (15:17 -0400)] 
remove should_nest behavior for contains_eager()

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

2 years agoupdate whatsnew/ migration
Mike Bayer [Fri, 23 Sep 2022 17:20:16 +0000 (13:20 -0400)] 
update whatsnew/ migration

The migration20 guide had a lot of "whats new" stuff in it,
which is moved to the whatsnew20 document.

Also moved most of the content regarding the reflection rewrite
into the whatsnew20 document and added some performance comparisons
to 1.4.

The sectioning for these two documents, as has happened for some
other documents I'm working on, has been modified to only use the
double-equals operator at the top.  This is strictly because my
vscode seems to be able to show me an .rst outline in the side panel
if I do it this way, and otherwise it's blank.

Change-Id: I1c89af8b6fd47a3c14f33becc6f9ee06b1743a0f

2 years agoauto-cast PG range types
Mike Bayer [Tue, 20 Sep 2022 16:21:14 +0000 (12:21 -0400)] 
auto-cast PG range types

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

2 years agoMerge "break out text() from TextualSelect for col matching" into main
mike bayer [Tue, 20 Sep 2022 02:34:31 +0000 (02:34 +0000)] 
Merge "break out text() from TextualSelect for col matching" into main