Commit Graph

5606 Commits

Author SHA1 Message Date
Mike Bayer dabebdefea update quickstart for 2.0
this is just so we can point people to something
while I get around to doing the rest of the docs

Change-Id: Ie818024a80ad30b76d7f7d6dc179939c246084c6
2022-06-12 12:32:55 -04:00
mike bayer b163099ada Merge "honor enum length in all cases" into main 2022-06-10 18:19:06 +00:00
mike bayer 6bbc1ef1e9 Merge "resolve large ints to BigInteger" into main 2022-06-10 18:18:35 +00:00
Mike Bayer bc0367c670 resolve large ints to BigInteger
The in-place type detection for Python integers, as occurs with an
expression such as ``literal(25)``, will now apply value-based adaption as
well to accommodate Python large integers, where the datatype determined
will be :class:`.BigInteger` rather than :class:`.Integer`. This
accommodates for dialects such as that of asyncpg which both sends implicit
typing information to the driver as well as is sensitive to numeric scale.

Fixes: #7909
Change-Id: I1cd3ec2676c9bb03ffedb600695252bd0037ba02
2022-06-10 13:23:20 -04:00
Mike Bayer 4274981156 honor enum length in all cases
The :paramref:`.Enum.length` parameter, which sets the length of the
``VARCHAR`` column for non-native enumeration types, is now used
unconditionally when emitting DDL for the ``VARCHAR`` datatype, including
when the :paramref:`.Enum.native_enum` parameter is set to ``True`` for
target backends that continue to use ``VARCHAR``. Previously the parameter
would be erroneously ignored in this case. The warning previously emitted
for this case is now removed.

Fixes: #7791
Change-Id: I91764546b56e9416479949be8a118cdc91ac5ed9
2022-06-10 13:21:26 -04:00
Mike Bayer f003360baa remove "undefer_pks" as a strategy option
The behavior of :func:`_orm.defer` regarding primary key and "polymorphic
discriminator" columns is revised such that these columns are no longer
deferrable, either explicitly or when using a wildcard such as
``defer('*')``. Previously, a wildcard deferral would not load
PK/polymorphic columns which led to errors in all cases, as the ORM relies
upon these columns to produce object identities. The behavior of explicit
deferral of primary key columns is unchanged as these deferrals already
were implicitly ignored.

Fixes: #7495
Change-Id: I76d9252426e86619bc142667670a3df75b4f5f6a
2022-06-10 12:27:03 -04:00
mike bayer b171f5d2e4 Merge "update cx_Oracle / oracledb LOB handling" into main 2022-06-10 15:11:44 +00:00
Mike Bayer 07678e0e34 update cx_Oracle / oracledb LOB handling
Adjustments made to the BLOB / CLOB / NCLOB datatypes in the cx_Oracle and
oracledb dialects, to improve performance based on recommendations from
Oracle developers.

References: https://github.com/oracle/python-cx_Oracle/issues/596
Fixes: #7494
Change-Id: I0d8cc3579140aa65cacf5b7d3373f7e1929a8f85
2022-06-10 10:48:17 -04:00
mike bayer 2e97c6a2e4 Merge "restore parameter escaping for public methods" into main 2022-06-09 16:03:53 +00:00
mike bayer 1eec436d68 Merge "dont transfer __weakref__ to regenerated class" into main 2022-06-09 16:01:26 +00:00
Mike Bayer e084b49360 Revert "document thread safety workaround for lambda statements"
This reverts commit bf40bade26.
2022-06-09 10:56:59 -04:00
Mike Bayer ab8b4f25ee restore parameter escaping for public methods
Adjusted the fix made for 🎫`8056` which adjusted the escaping of
bound parameter names with special characters such that the escaped names
were translated after the SQL compilation step, which broke a published
recipe on the FAQ illustrating how to merge parameter names into the string
output of a compiled SQL string. The change restores the escaped names that
come from ``compiled.params`` and adds a conditional parameter to
:meth:`.SQLCompiler.construct_params` named ``escape_names`` that defaults
to ``True``, restoring the old behavior by default.

Fixes: #8113
Change-Id: I9cbedb1080bc06d51f287fd2cbf26aaab1c74653
2022-06-09 10:14:13 -04:00
Mike Bayer cc7cc3c9ec dont transfer __weakref__ to regenerated class
Repaired a deprecation warning class decorator that was preventing key
objects such as :class:`_engine.Connection` from having a proper
``__weakref__`` attribute, causing operations like Python standard library
``inspect.getmembers()`` to fail.

Fixes: #8115
Change-Id: Ifd0bc2325fb9dc9e1431998c308b7fc081968373
2022-06-09 09:54:04 -04:00
mike bayer e1935b1711 Merge "fix race conditions in lambda statements" into main 2022-06-09 12:37:17 +00:00
mike bayer d93f952b46 Merge "suppport with_loader_criteria pickling w/ fixed callable" into main 2022-06-09 00:54:16 +00:00
Mike Bayer bf40bade26 document thread safety workaround for lambda statements
Change-Id: Idb7840ff64487ef985087a28bb6e96088e6a392e
References: #8098
2022-06-08 16:04:34 -04:00
mike bayer 73f867d996 Merge "graceful degrade for FKs not reflectable" into main 2022-06-08 17:13:28 +00:00
Mike Bayer 293b0e3dd8 suppport with_loader_criteria pickling w/ fixed callable
Fixed issue where a :func:`_orm.with_loader_criteria` option could not be
pickled, as is necessary when it is carried along for propagation to lazy
loaders in conjunction with a caching scheme. Currently, the only form that
is supported as picklable is to pass the "where criteria" as a fixed
module-level callable function that produces a SQL expression. An ad-hoc
"lambda" can't be pickled, and a SQL expression object is usually not fully
picklable directly.

Fixes: #8109
Change-Id: I49fe69088b0c7e58a0f22c67d2ea4e33752a5a73
2022-06-08 13:07:06 -04:00
Mike Bayer 117878f787 fix race conditions in lambda statements
Fixed multiple observed race conditions related to :func:`.lambda_stmt`,
including an initial "dogpile" issue when a new Python code object is
initially analyzed among multiple simultaneous threads which created both a
performance issue as well as some internal corruption of state.
Additionally repaired observed race condition which could occur when
"cloning" an expression construct that is also in the process of being
compiled or otherwise accessed in a different thread due to memoized
attributes altering the ``__dict__`` while iterated, for Python versions
prior to 3.10; in particular the lambda SQL construct is sensitive to this
as it holds onto a single statement object persistently. The iteration has
been refined to use ``dict.copy()`` with or without an additional iteration
instead.

Fixes: #8098
Change-Id: I4e0b627bfa187f1780dc68ec81b94db1c78f846a
2022-06-08 09:45:10 -04:00
mike bayer 1961e13214 Merge "Add support for the new oracle driver `oracledb`." into main 2022-06-07 18:46:36 +00:00
mike bayer c0736e0b2a Merge "migrate labels to new tutorial" into main 2022-06-07 17:02:20 +00:00
Federico Caselli fcbdae075b Add support for the new oracle driver `oracledb`.
Fixes: #8054
Change-Id: Idd7c1bbb7ca39499f53bdf59a63a6a9d65f144a5
2022-06-07 12:59:57 -04:00
Mike Bayer 93bc7ed534 graceful degrade for FKs not reflectable
Fixed bugs involving the :paramref:`.Table.include_columns` and the
:paramref:`.Table.resolve_fks` parameters on :class:`.Table`; these
little-used parameters were apparently not working for columns that refer
to foreign key constraints.

In the first case, not-included columns that refer to foreign keys would
still attempt to create a :class:`.ForeignKey` object, producing errors
when attempting to resolve the columns for the foreign key constraint
within reflection; foreign key constraints that refer to skipped columns
are now omitted from the table reflection process in the same way as
occurs for :class:`.Index` and :class:`.UniqueConstraint` objects with the
same conditions. No warning is produced however, as we likely want to
remove the include_columns warnings for all constraints in 2.0.

In the latter case, the production of table aliases or subqueries would
fail on an FK related table not found despite the presence of
``resolve_fks=False``; the logic has been repaired so that if a related
table is not found, the :class:`.ForeignKey` object is still proxied to the
aliased table or subquery (these :class:`.ForeignKey` objects are normally
used in the production of join conditions), but it is sent with a flag that
it's not resolvable. The aliased table / subquery will then work normally,
with the exception that it cannot be used to generate a join condition
automatically, as the foreign key information is missing. This was already
the behavior for such foreign key constraints produced using non-reflection
methods, such as joining :class:`.Table` objects from different
:class:`.MetaData` collections.

Fixes: #8100
Fixes: #8101

Change-Id: Ifa37a91bd1f1785fca85ef163eec031660d9ea4d
2022-06-07 12:34:47 -04:00
Mike Bayer 1c99edf1b9 migrate labels to new tutorial
other org changes and some sections from old tutorial
ported to new tutorial.

Change-Id: Ic0fba60ec82fff481890887beef9ed0fa271875a
2022-06-07 12:25:19 -04:00
mike bayer 6e538cf64a Merge "Generalize RETURNING and suppor for MariaDB / SQLite" into main 2022-06-05 20:40:41 +00:00
mike bayer cdafd5bb86 Merge "Fixed orm not applying fetch" into main 2022-06-04 18:21:02 +00:00
Federico Caselli 526e9bb6ae Fixed orm not applying fetch
Fixed an issue where :meth:`_sql.GenerativeSelect.fetch` would be
ignored when executing a statement using the ORM.

Fixes: #8091
Change-Id: I6790c7272a71278e90de2529c8bc8ae89e54e288
2022-06-04 12:02:49 -04:00
clach04 7f20d50693 Link to dialect for Actian Avalanche, Vector, Actian X, and Ingres (#8039) 2022-06-04 12:15:17 +02:00
Galen Rice 424e9e6212 docs: spelling error (#8088)
Leave off the last S for savings!
2022-06-04 12:07:43 +02:00
Mike Bayer ad86d32f7f emphasize expire_on_commit in detached error docs
issues like #8082 suggest users are still not
fully aware of the need to set this parameter
when dealing with detached objects.

Change-Id: I6f389fdbe18b9c977bfb8188fc4732dbd56884d9
2022-06-02 14:52:27 -04:00
Daniel Black 466ed5b53a Generalize RETURNING and suppor for MariaDB / SQLite
As almost every dialect supports RETURNING now, RETURNING
is also made more of a default assumption.

* the default compiler generates a RETURNING clause now
  when specified; CompileError is no longer raised.
* The dialect-level implicit_returning parameter now has
  no effect.   It's not fully clear if there are real world
  cases relying on the dialect-level parameter, so we will see
  once 2.0 is released.   ORM-level RETURNING can be disabled
  at the table level, and perhaps "implicit returning" should
  become an ORM-level option at some point as that's where
  it applies.
* Altered ORM update() / delete() to respect table-level
  implicit returning for fetch.
* Since MariaDB doesnt support UPDATE returning, "full_returning"
  is now split into insert_returning, update_returning, delete_returning
* Crazy new thing.  Dialects that have *both* cursor.lastrowid
  *and* returning.   so now we can pick between them for SQLite
  and mariadb.  so, we are trying to keep it on .lastrowid for
  simple inserts with an autoincrement column, this helps with
  some edge case test scenarios and i bet .lastrowid is faster
  anyway.  any return_defaults() / multiparams etc then we
  use returning
* SQLite decided they dont want to return rows that match in
  ON CONFLICT.  this is flat out wrong, but for now we need to
  work with it.

Fixes: #6195
Fixes: #7011
Closes: #7047
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7047
Pull-request-sha: d25d5ea3ab

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I9908ce0ff7bdc50bd5b27722081767c31c19a950
2022-06-02 12:51:20 -04:00
mike bayer 6e8bc369d2 Merge "propagate proxy_key from WrapsColumnExpression" into main 2022-06-01 17:27:13 +00:00
mike bayer 7b6fb299bb Merge "add backend agnostic UUID datatype" into main 2022-06-01 16:13:36 +00:00
Mike Bayer 14250f2668 propagate proxy_key from WrapsColumnExpression
this allows cast() of a label() to propagate the
proxy key outwards in the same way that it apparently
works at the SQL level.

This is stuffing even more rules into naming so basically
seeing how far we can go without other cases starting
to fail.

Fixes: #8084
Change-Id: I20bd97dae798fee6492334c06934e807d0f269ef
2022-06-01 12:11:19 -04:00
Mike Bayer 349a7c5e0e add backend agnostic UUID datatype
Added new backend-agnostic :class:`_types.Uuid` datatype generalized from
the PostgreSQL dialects to now be a core type, as well as migrated
:class:`_types.UUID` from the PostgreSQL dialect. Thanks to Trevor Gross
for the help on this.

also includes:

* corrects some missing behaviors in the suite literal fixtures
  test where row round trips weren't being correctly asserted.
* fixes some of the ISO literal date rendering added in
  952383f9ee for #5052 to truncate datetime strings for date/time
  datatypes in the same way that drivers typically do for bound
  parameters; this was not working fully and wasn't caught by the
  broken test fixture

Fixes: #7212
Change-Id: I981ac6d34d278c18281c144430a528764c241b04
2022-06-01 11:40:56 -04:00
mike bayer 79dbe94bb4 Merge "Support handle_error for pre_ping" into main 2022-06-01 13:58:17 +00:00
Mike Bayer 01ffcf387f cherry-pick changelog update for 1.4.38 2022-05-31 17:28:09 -04:00
Mike Bayer cfee6a2537 cherry-pick changelog from 1.4.37 2022-05-31 17:28:08 -04:00
Mike Bayer 1e8e4ace63 changelog fixes
Change-Id: Id3fc3019f8eb799aa5adf6ca28e0aeedc0da31dd
2022-05-31 17:21:39 -04:00
mike bayer 6eeee37190 Merge "Handle dead-connection errors for users of python-oracledb" into main 2022-05-31 20:42:21 +00:00
mike bayer f1b8f74a18 Merge "raise informative error when selectable can't be extended" into main 2022-05-31 19:47:49 +00:00
Patrick Gerken 1e1431fbfb Update declarative_styles.rst: Update code example to attrs TNG usage. (#8072)
* Update declarative_styles.rst

Update docs to new style usage of attrs.
This is the default since December 2021.
While the old style still works, the newer one looks much nicer and is likely to be dominant pretty quickly. Imho.

* Update declarative_styles.rst

* Update declarative_styles.rst
2022-05-31 21:42:35 +02:00
Mike Bayer ad14471bc9 Support handle_error for pre_ping
The :meth:`.DialectEvents.handle_error` event is now moved to the
:class:`.DialectEvents` suite from the :class:`.EngineEvents` suite, and
now participates in the connection pool "pre ping" event for those dialects
that make use of disconnect codes in order to detect if the database is
live. This allows end-user code to alter the state of "pre ping". Note that
this does not include dialects which contain a native "ping" method such as
that of psycopg2 or most MySQL dialects.

Fixes: #5648
Change-Id: I353d84a4f66f309d2467b7e67621db6b8c70411e
2022-05-31 15:06:28 -04:00
Mike Bayer d1142c6e9f raise informative error when selectable can't be extended
An informative error is raised for the use case where
:meth:`.Insert.from_select` is being passed a "compound select" object such
as a UNION, yet the INSERT statement needs to append additional columns to
support Python-side or explicit SQL defaults from the table metadata. In
this case a subquery of the compound object should be passed.

Fixes: #8073
Change-Id: Ic4a5dbf84ec49d2451901be05cb9cf6ae93f02b7
2022-05-31 13:00:14 -04:00
Christopher Jones 775ce5165e Handle dead-connection errors for users of python-oracledb
Added two new error codes for Oracle disconnect handling to support early
testing of the new "python-oracledb" driver released by Oracle.

Fixes: #8066
Closes: #8065
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8065
Pull-request-sha: d630b8457a

Change-Id: Ib14dbb888597b1087b1bb7c505ccad59df226177
(cherry picked from commit 2bf00472bfafd8fd0cca5b4fe55ff4faf1a1279e)
(cherry picked from commit 8564e2abf9)
2022-05-31 10:08:42 -04:00
Josep Pascual Badia d97de97eff repair incorrect "cursor" var name in connection faq
Closes: #8075
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8075
Pull-request-sha: 34e5eaf387

Change-Id: Iab8cdc9f8da68ac955eea75efeba263d0a9dcb7b
2022-05-30 10:42:27 -04:00
mike bayer 4fb6aca6cf Merge "remove "deannotate" from column_property expression" into main 2022-05-29 21:36:40 +00:00
mike bayer c6b6b7bb75 Merge "move bindparam quote application from compiler to default" into main 2022-05-29 21:34:37 +00:00
Mike Bayer 335cdea7c7 remove "deannotate" from column_property expression
Fixed issue where using a :func:`_orm.column_property` construct containing
a subquery against an already-mapped column attribute would not correctly
apply ORM-compilation behaviors to the subquery, including that the "IN"
expression added for a single-table inherits expression would fail to be
included.

This fix involves a few tweaks in the ORM adaptation logic,
including a missing "parententity" adaptation on the mapper
side.  The specific mechanics here have a lot of moving parts
so we will continue to add tests to assert these cases.  In
particular a more complete test for issue #2316 is added
that was relying upon the deannotate happening here.

Fixes: #8064
Change-Id: Ia85dd12dcf6e7c002b30de4a27d7aa66cb3cd20e
2022-05-29 16:10:54 -04:00
Mike Bayer cac8de9ab2 move bindparam quote application from compiler to default
in 296c84313a for #5653 we generalized Oracle's
parameter escaping feature into the compiler, so that it could also
work for PostgreSQL.  The compiler used quoted names within parameter
dictionaries, which then led to the complexity that all functions
which interpreted keys from the compiled_params dict had to
also quote the param names to use the dictionary.  This
extra complexity was not added to the ORM peristence.py however,
which led to the versioning id feature being broken as well as
other areas where persistence.py relies on naming schemes present
in context.compiled_params.  It also was not added to the
"processors" lookup which led to #8053, that added this escaping
to that part of the compiler.

To both solve the whole problem as well as simplify the compiler
quite a bit, move the actual application of the escaped names
to be as late as possible, when default.py builds the final list
of parameters.  This is more similar to how it worked previously
where OracleExecutionContext would be late-applying these
escaped names.   This re-establishes context.compiled_params as
deterministically named regardless of dialect in use and moves
out the complexity of the quoted param names to be only at the
cursor.execute stage.

Fixed bug, likely a regression from 1.3, where usage of column names that
require bound parameter escaping, more concretely when using Oracle with
column names that require quoting such as those that start with an
underscore, or in less common cases with some PostgreSQL drivers when using
column names that contain percent signs, would cause the ORM versioning
feature to not work correctly if the versioning column itself had such a
name, as the ORM assumes certain bound parameter naming conventions that
were being interfered with via the quotes. This issue is related to
🎫`8053` and essentially revises the approach towards fixing this,
revising the original issue 🎫`5653` that created the initial
implementation for generalized bound-parameter name quoting.

Fixes: #8056
Change-Id: I57b064e8f0d070e328b65789c30076f6a0ca0fef
2022-05-29 14:36:20 -04:00