Commit Graph

15466 Commits

Author SHA1 Message Date
mike bayer 6201b4d886 Merge "ORM bulk insert via execute" into main 2022-09-26 01:17:44 +00:00
mike bayer f81fdd9a90 Merge "implement batched INSERT..VALUES () () for executemany" into main 2022-09-26 01:17:27 +00:00
mike bayer 6072bebd19 Merge "warn for local-only column in remote side" into main 2022-09-25 23:15:46 +00:00
Mike Bayer 29838ef584 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
2022-09-25 16:17:33 -04:00
Federico Caselli 65aa9b8a98 Use aggregate order by instead of order by in subquery
Fixes: #8561
Change-Id: I2d9f6bd895061bf8fbc66723930716670791d896
2022-09-25 18:20:22 +02:00
Mike Bayer a8029f5a7e 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
2022-09-24 11:18:01 -04:00
Mike Bayer 75ab50869b add missing changelog for #8569
Missed this in 57b400f079.  have no idea how.

Fixes: #8569
Change-Id: I4cec98d8c963930ef822bfd53d8a60a20be02894
2022-09-24 11:16:16 -04:00
Mike Bayer 2bcc97da42 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
2022-09-24 11:15:32 -04:00
Federico Caselli 332188e568 Add oracledb to whatsnew list.
Change-Id: I8153a6af599a8ce6dfb45bbda13f01801eda3b6e
2022-09-24 13:05:44 +02:00
mike bayer beb4376c5e Merge "Tighten password security by removing URL.__str__" into main 2022-09-24 01:02:16 +00:00
mike bayer 8e59de9cc1 Merge "remove should_nest behavior for contains_eager()" into main 2022-09-24 01:00:10 +00:00
Yassen Damyanov 3333c6623f 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: d1f1127f75

Change-Id: If756c8073ff99ac83876d9833c8fe1d7c76211f9
2022-09-23 17:27:30 -04:00
Mike Bayer 57b400f079 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
2022-09-23 17:17:02 -04:00
Mike Bayer d50bbd5674 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
2022-09-23 13:37:50 -04:00
Mike Bayer 9ae645d5d1 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
2022-09-20 12:34:46 -04:00
mike bayer 214d1ad7c3 Merge "break out text() from TextualSelect for col matching" into main 2022-09-20 02:34:31 +00:00
mike bayer aab6005dda Merge "add raiseload to load_only()" into main 2022-09-19 23:30:23 +00:00
Mike Bayer c9af2ebf5e break out text() from TextualSelect for col matching
Fixed issue where mixing "*" with additional explicitly-named column
expressions within the columns clause of a :func:`_sql.select` construct
would cause result-column targeting to sometimes consider the label name or
other non-repeated names to be an ambiguous target.

Fixes: #8536
Change-Id: I3c845eaf571033e54c9208762344f67f4351ac3a
2022-09-19 18:39:18 -04:00
Mike Bayer 9020e104eb add raiseload to load_only()
currently this can't be finessed in another way,
at least not easily.   The deferred() that it sets up
doesn't seem to be cancellable.  in any case, this is more consistent
API with that of defer().

Change-Id: I30fca1cc371c9102d013cda8e23a522eea1033f8
2022-09-19 18:27:28 -04:00
dependabot[bot] 16359c4121 Bump pypa/cibuildwheel from 2.10.0 to 2.10.1 (#8537)
Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.10.0 to 2.10.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.0...v2.10.1)

---
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>
2022-09-19 21:12:02 +02:00
mike bayer e7700b4a88 Merge "change verbiage stating exact compliance with RFC-1738" into main 2022-09-17 17:40:11 +00:00
mike bayer 2ba8bf01ea Merge "Improve array_agg and Array processing" into main 2022-09-17 14:55:04 +00:00
Mike Bayer c88bb2167b change verbiage stating exact compliance with RFC-1738
As long as we aren't using urlparse() to parse URLs,
we are not RFC-1738 compliant.   As we accept underscores
in the scheme and not dashes or dots, we are not
RFC-1738 compliant, so emulate language like
that of PostgreSQL [1] that we "generally follow" this
scheme but include some exceptions.

[1] https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
Fixes: #8519

Change-Id: I2d7e55d9df17aed122cebb2c4c315f56c06a3da5
2022-09-17 10:41:48 -04:00
Mike Bayer f0bcd57f9e remove obtuse section about "bundled bind parameters"
Just looking for basics on insert in the first pages
of the tutorial I see this weird detour into something that
nobody ever uses and definitely isn't going to make sense
to the people I see complaining about our docs on twitter,
remove this.   the tutorial probably needs a big sweep
for wordy obtuse things.  the userbase is changing and
we really have a lot of brand-new-to-programming types coming
in.

Change-Id: I3bb11f0399e55edbb8f874e7eb63c40616b04e8b
2022-09-17 10:18:56 -04:00
Federico Caselli 02fe382d6b Improve array_agg and Array processing
The :class:`_functions.array_agg` will now set the array dimensions to 1.
Improved :class:`_types.ARRAY` processing to accept ``None`` values as
value of a multi-array.

Fixes: #7083
Change-Id: Iafec4f77fde9719ccc7c8535bf6235dbfbc62102
2022-09-17 13:12:35 +02:00
mike bayer f582618afe Merge "Ignore max_overflow when pool_size is 0" into main 2022-09-16 22:28:45 +00:00
mike bayer 27e0225656 Merge "Support GROUP BY ROLLUP on MySql/MariaDB" into main 2022-09-16 22:27:14 +00:00
mike bayer 8f8398a485 Merge "catch exception for system_views also" into main 2022-09-16 22:26:25 +00:00
Federico Caselli 5bf27c0958 fix documentation typos
Closes #8527
Change-Id: I0354f3953075fa35a84b09ad45fd850d8889c992

(cherry picked from commit 02b1ed5220)
2022-09-16 23:51:52 +02:00
Federico Caselli 20917c5918 Ignore max_overflow when pool_size is 0
The :class:`_pool.QueuePool` now ignores ``max_overflow`` when
``pool_size=0``, properly making the pool unlimited in all cases.

Fixes: #8523
Change-Id: Ifc32eb47a281c4b3acf357352f07b9b8a73d1b6f
2022-09-15 22:42:08 +02:00
Federico Caselli 04ea009a83 Merge "Improved usage of `asyncio.shield()`" into main 2022-09-15 20:18:58 +00:00
Federico Caselli d9ecad5af6 Merge "Use `; instead of select 1` to ping PostgreSQL" into main 2022-09-15 20:18:39 +00:00
mike bayer 002199ba42 Merge "Add type awareness to evaluator" into main 2022-09-15 15:30:23 +00:00
Federico Caselli 2e302b2d8f Use `; instead of select 1` to ping PostgreSQL
Fixes: #8491
Change-Id: I941d2a3cf92e5609e2045a53cec94522340951db
2022-09-15 09:31:44 -04:00
Federico Caselli 939f77c94b Improved usage of `asyncio.shield()`
Fixes: #8516
Change-Id: Ifd8f5e5f42d9fbcd5b8d00bddc81ff6be690a75e
2022-09-15 09:02:33 -04:00
Mike Bayer 0ee7d693b8 catch exception for system_views also
Fixed yet another regression in SQL Server isolation level fetch (see
🎫`8231`, 🎫`8475`), this time with "Microsoft Dynamics CRM
Database via Azure Active Directory", which apparently lacks the
``system_views`` view entirely. Error catching has been extended that under
no circumstances will this method ever fail, provided database connectivity
is present.

Fixes: #8525
Change-Id: I76a429e3329926069a0367d2e77ca1124b9a059d
2022-09-15 08:42:34 -04:00
Mike Bayer 310dd2e6a7 add missing doc for mariadb-connector
this module was never indexed.   kind of a major oversight

Change-Id: I4389a2ca3900edc70130fbae66195605a5704362
2022-09-14 23:09:08 -04:00
dependabot[bot] de173b600b Bump pypa/cibuildwheel from 2.9.0 to 2.10.0 (#8517)
Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.9.0 to 2.10.0.
- [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.9.0...v2.10.0)

---
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>
2022-09-13 21:03:28 +02:00
Mike Bayer 14b634d706 Add type awareness to evaluator
Fixed regression where using ORM update() with synchronize_session='fetch'
would fail due to the use of evaluators that are now used to determine the
in-Python value for expressions in the the SET clause when refreshing
objects; if the evaluators make use of math operators against non-numeric
values such as PostgreSQL JSONB, the non-evaluable condition would fail to
be detected correctly. The evaluator now limits the use of math mutation
operators to numeric types only, with the exception of "+" that continues
to work for strings as well. SQLAlchemy 2.0 may alter this further by
fetching the SET values completely rather than using evaluation.

Fixes: #8507
Change-Id: Icf7120ccbf4266499df6bb3e05159c9f50971d69
2022-09-13 11:18:19 -04:00
Federico Caselli efbe38d8e8 Support GROUP BY ROLLUP on MySql/MariaDB
The ``ROLLUP`` function will now correctly render ``WITH ROLLUP`` on
MySql and MariaDB, allowing the use of group by rollup with these
backend.

Fixes: #8503
Change-Id: I9289af3a39ca667a2f0f84f73346ebd4b091fedd
2022-09-09 21:29:53 +02:00
mike bayer 479dbc99e7 Merge "additional de-stringify pass for unions" into main 2022-09-08 19:00:08 +00:00
mike bayer b0e5667a79 Merge "implement icontains, istartswith, iendswith operators" into main 2022-09-08 18:19:46 +00:00
Mike Bayer fcd298e1af additional de-stringify pass for unions
the change in c3cfee5b00 took out
a pass for de-stringify that broke some un-tested cases
for Optional with future annotations mode.   Adding tests
for this revealed that this was a subset of
a more general case where Union is presented
with ForwardRefs inside of it matching up within the type
map, which wasn't working before either, fixed that as well with
an additional de-stringify for elements within the Union.

Fixes: #8478
Change-Id: I8804cf6c67f14d10804584e1cddd2cfaa2376654
2022-09-08 14:15:50 -04:00
Mike Bayer e0d441bba8 limit sqlite UPDATE..FROM to 3.33.0
Change-Id: I25ad8a9d6f657f85dd216b4d624f711225ef9f04
References: https://www.sqlite.org/lang_update.html
2022-09-08 13:46:41 -04:00
mike bayer 36803bc567 Merge "enable UPDATE..FROM for SQLite" into main 2022-09-08 16:31:35 +00:00
Matias Martinez Rebori 93aaf16727 implement icontains, istartswith, iendswith operators
Added long-requested case-insensitive string operators
:meth:`_sql.ColumnOperators.icontains`,
:meth:`_sql.ColumnOperators.istartswith`,
:meth:`_sql.ColumnOperators.iendswith`, which produce case-insensitive
LIKE compositions (using ILIKE on PostgreSQL, and the LOWER() function on
all other backends) to complement the existing LIKE composition operators
:meth:`_sql.ColumnOperators.contains`,
:meth:`_sql.ColumnOperators.startswith`, etc. Huge thanks to Matias
Martinez Rebori for their meticulous and complete efforts in implementing
these new methods.

Fixes: #3482
Closes: #8496
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8496
Pull-request-sha: 7287e2c436

Change-Id: I9fcdd603716218067547cc92a2b07bd02a2c366b
2022-09-08 12:15:23 -04:00
Mike Bayer 885c61cf22 enable UPDATE..FROM for SQLite
The SQLite dialect now supports UPDATE..FROM syntax, for UPDATE statements
that may refer to additional tables within the WHERE criteria of the
statement without the need to use subqueries. This syntax is invoked
automatically when using the :class:`_dml.Update` construct when more than
one table or other entity or selectable is used.

Fixes: #7185
Change-Id: I27e94ace9ff761cc45e652fa1abff8cd1f42fec5
2022-09-07 19:10:53 -04:00
Mike Bayer cc72081b0c add docs for session.get()
also use the term "primary key" a bit more

Change-Id: Ib654b30a9d06a2aeed019b4754db920afe05d774
References: https://twitter.com/encthenet/status/1567644850471989248
2022-09-07 19:00:31 -04:00
Mike Bayer 06fe424256 cherry-pick changelog update for 1.4.42 2022-09-06 20:58:38 -04:00
Mike Bayer b31ec4adf9 cherry-pick changelog from 1.4.41 2022-09-06 20:58:37 -04:00