Commit Graph

12082 Commits

Author SHA1 Message Date
Mike Bayer c4e7feddd7 Don't assume m2o key is present in the dictionary
Fixed regression caused by new selectinload for many-to-one logic where
a primaryjoin condition not based on real foreign keys would cause
KeyError if a related object did not exist for a given key value on the
parent object.

Fixes: #4777
Change-Id: I4ba96318302be68abe0e8c3611684087a04a2322
(cherry picked from commit 8f5b65f431)
2019-07-23 09:25:59 -04:00
Mike Bayer c46cdd3d92 Version 1.3.7 placeholder 2019-07-21 17:10:02 -04:00
Mike Bayer 8f3ffc4a23 - 1.3.6 rel_1_3_6 2019-07-21 16:37:07 -04:00
Min ho Kim 00e7a0eeae Fix typos
(cherry picked from commit 7e588aadaa)

Change-Id: Ibd2fbf365ed2b8f0d1765ef7271d28ab3a2d073a
2019-07-21 16:30:31 -04:00
Mike Bayer 5f72a69e9f Optimize out JOIN for selectinload with many to one
The optimzation applied to selectin loading in 🎫`4340` where a JOIN
is not needed to eagerly load related items is now applied to many-to-one
relationships as well, so that only the related table is queried for a
simple join condition.   In this case, the related items are queried
based on the value of a foreign key column on the parent; if these columns
are deferred or otherwise not loaded on any of the parent objects in
the collection, the loader falls back to the JOIN method.

Fixes: #4775
Change-Id: I398e0d276789ce6e0019d213a37bdf99d24ec290
(cherry picked from commit a5a66f1e58)
2019-07-19 17:56:07 -04:00
mike bayer ec1dce7849 Merge "Include 'p' for get_indexes() query" into rel_1_3 2019-07-19 20:24:36 +00:00
Mike Bayer de1ad759ab Include 'p' for get_indexes() query
Added support for reflection of indexes on PostgreSQL partitioned tables,
which was added to PostgreSQL as of version 11.

Fixes: #4771
Change-Id: I9e8e75c4d8a667b4d52d12afbd384e0a8db00466
(cherry picked from commit a739a3449f)
2019-07-19 13:19:17 -04:00
Mike Bayer 19b6c15211 Support tuple IN VALUES for SQLite, others
Added support for composite (tuple) IN operators with SQLite, by rendering
the VALUES keyword for this backend.  As other backends such as DB2 are
known to use the same syntax, the syntax is enabled in the base compiler
using a dialect-level flag ``tuple_in_values``.   The change also includes
support for "empty IN tuple" expressions for SQLite when using "in_()"
between a tuple value and an empty set.

Fixes: #4766
Change-Id: I416e1af29b31d78f9ae06ec3c3a48ef6d6e813f5
(cherry picked from commit 88168db8e9)
2019-07-19 13:10:23 -04:00
mike bayer 11ca002ac4 Merge "Fixes for uselist=True with m2o relationships" into rel_1_3 2019-07-18 16:55:33 +00:00
Mike Bayer f1f055e51b Fix regression for self-ref join to self error message
Fixed regression caused by 🎫`4365` where a join from an entity to
itself without using aliases no longer raises an informative error message,
instead failing on an assertion.  The informative error condition has been
restored.

Fixes: #4773
Change-Id: Iabeb56f3f0c2a40e350fd7c69f07c02dc9804c2c
(cherry picked from commit 736186f840)
2019-07-18 11:14:54 -04:00
Mike Bayer 86f4ae3266 Fixes for uselist=True with m2o relationships
Fixed bug where a many-to-one relationship that specified ``uselist=True``
would fail to update correctly during a primary key change where a related
column needs to change.

Fixed bug where the detection for many-to-one or one-to-one use with a
"dynamic" relationship, which is an invalid configuration, would fail to
raise if the relationship were configured with ``uselist=True``.  The
current fix is that it warns, instead of raises, as this would otherwise be
backwards incompatible, however in a future release it will be a raise.

Fixes: #4772
Change-Id: Ibd5d2f7329ff245c88118e2533fc8ef42a09fef3
(cherry picked from commit 5e8c7c88de)
2019-07-18 10:59:38 -04:00
Denis Kataev 194c7d3e3a Small text error in json field doc
Small fix json field doc

(cherry picked from commit 7b8ff3c335)
2019-07-17 20:50:56 -04:00
Denis Kataev d1cf7b31b9 Fix doc for #4765
(cherry picked from commit 86d8b12a6b)
2019-07-17 20:47:37 -04:00
Mike Bayer cfac04da2a Intercept unresolveable comparator attrbute error for attr access
Fixed bug where a synonym created against a mapped attribute that does not
exist yet, as is the case when it refers to backref before mappers are
configured, would raise recursion errors when trying to test for attributes
on it which ultimately don't exist (as occurs when the classes are run
through Sphinx autodoc), as the unconfigured state of the synonym would put
it into an attribute not found loop.

Fixes: #4767
Change-Id: I9aade8628349fbf538181a0049416cec0a17179c
(cherry picked from commit 234723fa29)
2019-07-17 10:42:17 -04:00
Mike Bayer 7e161e8347 Pin pycodestyle
PyCQA/pydocstyle#375

Change-Id: Ifc7ead440010e89474300407fea5770956ff1aaf
(cherry picked from commit 1a9f5754e0)
2019-07-17 10:41:19 -04:00
Peter Schutt 31c9ef2fd8 SyntaxError in on_duplicate_key_update() example.
(cherry picked from commit 26ef5ed862)
2019-07-15 09:19:34 -04:00
Mike Bayer 0eb7a5b78a self_group() for FunctionFilter
Fixed issue where the :class:`.array_agg` construct in combination with
:meth:`.FunctionElement.filter` would not produce the correct operator
precedence between the FILTER keyword and the array index operator.

Fixes: #4760
Change-Id: Ic662cd3da3330554ec673bafd80495b3f1506098
(cherry picked from commit 116faee662)
2019-07-12 22:45:41 -04:00
Mike Bayer 75fdcacc85 Add performance improvement for Enum w/ Python 2 enum library
Adjusted the initialization for :class:`.Enum` to minimize how often it
invokes the ``.__members__`` attribute of a given PEP-435 enumeration
object, to suit the case where this attribute is expensive to invoke, as is
the case for some popular third party enumeration libraries.

Fixes: #4758
Change-Id: Iffeb854c67393bdcb288944fc357a074e20e1325
(cherry picked from commit 2cc7308c96)
2019-07-11 00:21:08 -04:00
Mike Bayer 6e0fcfd560 Support multidimensional array literals in Postgresql
Added support for multidimensional Postgresql array literals via nesting
the :class:`.postgresql.array` object within another one.  The
multidimensional array type is detected automatically.

Fixes: #4756
Change-Id: Ie2107ad3cf291112f6ca330dc90dc15a0a940cee
(cherry picked from commit 6bc7e0bfa9)
2019-07-08 16:22:04 -04:00
Mike Bayer 375c91b591 Ensure .engine is part of Connectable interface, implement as descriptor
Fixed bug where using reflection function such as :meth:`.MetaData.reflect`
with an :class:`.Engine` object that had execution options applied to it
would fail, as the resulting :class:`.OptionEngine` proxy object failed to
include a ``.engine`` attribute used within the reflection routines.

Fixes: #4754
Change-Id: I6c342af5c6db6fe362b9d25f3f26d6859f62f87a
(cherry picked from commit 3238d953b4)
2019-07-08 11:13:08 -04:00
Mike Bayer 5edd50c0c8 Add additional parsing to extract the "MariaDB" keyword from version string
Enhanced MySQL/MariaDB version string parsing to accommodate for exotic
MariaDB version strings where the "MariaDB" word is embedded among other
alphanumeric characters such as "MariaDBV1".   This detection is critical in
order to correctly accomodate for API features that have split between MySQL
and MariaDB such as the "transaction_isolation" system variable.

Fixes: #4624
Change-Id: Iba4b56535855629a974b1e24e012b07383d24199
(cherry picked from commit 95dd8768d4)
2019-07-06 09:55:34 -04:00
Mike Bayer 332eff7ddf Repair json example in tutorial to suit non-present sqlite support
SQLite on CI doesn't have json functions (centos) so even
though SQLAlchemy supports it in this version, use the MySQL
compiler for the example.

Change-Id: If896273adbab2e3fdb995272f6e55de420aee220
(cherry picked from commit 1ce98ca83a)
2019-07-05 18:12:22 -04:00
Mike Bayer 3156f275f6 Adjust JSON verbiage about "implied" datatype
SQLite and MariaDB (not MySQL) has an "implied" JSON,
MySQL has it directly

Change-Id: I2e1744de96ac4e241dc647ae2214b63cdad33428
(cherry picked from commit 1abbdf0d52)
2019-07-05 16:16:57 -04:00
Mike Bayer 0b7a99c4bd Rename tutorial section to "Using Aliases and Subqueries"
add some verbiage to start differentiating a subquery from
an alias.

Also, get rid of a very strange note to use ``.correlate(None)``
on a non-scalar subquery; this is unnecessary and confusing.

Change-Id: I83b2fd1275c719a32bb74060756d61bc51b52892
(cherry picked from commit f4f9ec1c2f)
2019-07-05 15:56:38 -04:00
Mike Bayer d36c7d0601 Note DBAPIs and dialects that we don't support
Since we have strong CI for the DBAPIs and dialects that are actively
supported, this indicates that those DBAPIs that aren't in CI are
continuing to fall behind in support, to the point where we can
not address issues that may arise. As such, the Sybase and Firebird
dialects overall are moving into an explicit "not supported" zone
where we would like to eventually remove them.   Additionally,
a pass is made through legacy MySQL and PostgreSQL DBAPI dialects
as well as those which we aren't able to include in CI to note
that these DBAPIs aren't actively supported by the project.

Change-Id: I61f1515b97b741b7534b54e434e3e47065df7b5d
(cherry picked from commit 4bd4bae5c1)
2019-07-05 12:22:26 -04:00
Mike Bayer 908b5f1d35 Squashed commit of the following:
commit d4f3bedc74
Author: Carson Ip <carsonip@users.noreply.github.com>
Date:   Fri Jul 5 11:20:12 2019 +0800

    Fix typo in docstring

commit a3e4b05744
Author: Carson Ip <carsonip@users.noreply.github.com>
Date:   Fri Jul 5 11:14:57 2019 +0800

    Fix typo in docstring

Change-Id: Ifa2ebff5629bf970e5fac28bba64d501376cfae9
(cherry picked from commit 28daa34cb8)
2019-07-05 10:06:49 -04:00
Mike Bayer 1a4e136bdc Add tutorial section for cast(), type_coerce()
Change-Id: I49f635f0ad4d07abe8ef2681c9660ec7fcf5f99b
(cherry picked from commit e03f7ab50e)
2019-07-04 11:17:40 -04:00
Mike Bayer 60ba866fae Rework proxy_cache fix to restore performance
Adjustment to the fix made in I7fb134cac3604f8fe62e220fb24a0945d0a1c56f.

Fixes: #4747
Change-Id: I2f1010b0abc1faa892f5e346e58f9c4a3867622f
(cherry picked from commit 9b52c8ae92)
2019-07-02 18:23:06 -04:00
Mike Bayer 4a941414b7 Clear proxy_set cache when creating an annotated column
Fixed an unlikely issue where the "corresponding column" routine for unions
and other :class:`.CompoundSelect` objects could return the wrong column in
some overlapping column situtations, thus potentially impacting some ORM
operations when set operations are in use, if the underlying
:func:`.select` constructs were used previously in other similar kinds of
routines, due to a cached value not being cleared.

Fixes: #4747
Change-Id: I7fb134cac3604f8fe62e220fb24a0945d0a1c56f
(cherry picked from commit 6636cd9d25)
2019-07-02 09:58:50 -04:00
Mike Bayer e07cc75b97 A few doc tweaks for alias / order_by / group_by
Change-Id: Ib3b46b45735529d68ebfb3784de4de5d2d0f4abc
(cherry picked from commit 3b60ccaed4)
2019-07-01 13:10:12 -04:00
mike bayer 427b5abd09 Merge "CAST bind values against SQL Server sys into NVARCHAR" into rel_1_3 2019-06-28 17:24:00 +00:00
Denis Kataev dadbc89b68 Test for _ORMJoin and fix issue
Fixed an issue where the :meth:`.orm._ORMJoin.join` method, which is a
not-internally-used ORM-level method that exposes what is normally an
internal process of :meth:`.Query.join`, did not propagate the ``full`` and
``outerjoin`` keyword arguments correctly.  Pull request courtesy Denis
Kataev.

Fixes: #4713
Closes: #4744
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4744
Pull-request-sha: ac88706149

Change-Id: If9a30a4ca56c430ddd6fec29ad519556e9001c4b
(cherry picked from commit a02ed10d5f)
2019-06-28 11:28:50 -04:00
Mike Bayer ebf96c34a2 CAST bind values against SQL Server sys into NVARCHAR
Ensured that the queries used to reflect indexes and view definitions will
explicitly CAST string parameters into NVARCHAR, as many SQL Server drivers
frequently treat string values, particularly those with non-ascii
characters or larger string values, as TEXT which often don't compare
correctly against VARCHAR characters in SQL Server's information schema
tables for some reason.    These CAST operations already take place for
reflection queries against SQL Server ``information_schema.`` tables but
were missing from three additional queries that are against ``sys.``
tables.

Fixes: #4745
Change-Id: I3056533bf1a1e8ef17742879d369ab13f8b704ea
(cherry picked from commit 345f2eb05b)
2019-06-28 11:17:47 -04:00
Mike Bayer ce9de9fff6 Add Load.options() for hierchical construction of loader options
Added new loader option method :meth:`.Load.options` which allows loader
options to be constructed hierarchically, so that many sub-options can be
applied to a particular path without needing to call :func:`.defaultload`
many times.  Thanks to Alessio Bogon for the idea.

Also applies a large pass to the loader option documentation which
needed improvement.

Fixes: #4736

Change-Id: I93c453e30a20c074f27e87cf7e95b13dd3f2b494
(cherry picked from commit f0d1a5364f)
2019-06-27 23:28:12 -04:00
Mike Bayer 22131f0629 Unwrap TIMESTAMP when doing an isinstance()
Fixed bug where the special logic to render "NULL" for the
:class:`.TIMESTAMP` datatype when ``nullable=True`` would not work if the
column's datatype were a :class:`.TypeDecorator` or a :class:`.Variant`.
The logic now ensures that it unwraps down to the original
:class:`.TIMESTAMP` so that this special case NULL keyword is correctly
rendered when requested.

Fixes: #4743
Change-Id: I02b22dfa3db06daea37b044e2206a8569e2e5d22
(cherry picked from commit 401a2691fb)
2019-06-27 17:51:28 -04:00
Mike Bayer eaba0a9d93 Revert 1ed2f16215 black target version
Unfortunately target version py27 makes Black want to break
print functions, even if you put a "from __future__ import print_function"
at the top, so it is being inconsistent in its "we've decided this
is a python 2 file" logic and basically this thing really needs
command line arguments

Change-Id: Iefa62df4224b9620e764b16b1c390647f948e85f
(cherry picked from commit b0cacfdd4f)
2019-06-27 16:29:54 -04:00
Mike Bayer 9e783958a7 Disable black auto-version detection
We're targeting Python 2.7 still so ensure black does not
add trailing commas

Change-Id: I9896b3a71de855d834f0133fd2d6213aae40fc9d
(cherry picked from commit 1ed2f16215)
2019-06-24 13:21:08 -04:00
Mike Bayer 424294156c Register pytest assertion rewriting on sqlalchemy.testing.assertions
Since our various eq_(), ne_() etc. functions use assert, pytest
can rewrite this module using its enhanced string reporting.
very helpful for comparing SQL strings

Change-Id: Ia71328401fd7965bcb14eb1ccea0dc48a8f2c3ea
(cherry picked from commit 6da5242953)
2019-06-21 16:03:28 -04:00
Mike Bayer 8b2ad56981 Enable F841
This is a very useful assertion which prevents unused variables
from being set up allows code to be more readable and sometimes
even more efficient.  test suites seem to be where the most
problems are and there do not seem to be documentation examples
that are using this, or at least the linter is not taking effect
within rst blocks.

Change-Id: I2b3341d8dd14da34879d8425838e66a4b9f8e27d
(cherry picked from commit 190e0139e8)
2019-06-21 10:18:17 -04:00
Mike Bayer c8df8a1b37 Add option for "sparse" backend tests and apply to memusage
The memusage tests are extremely time and memory intensive,
and when CI runs against MySQL or Postgresql there are many
database/driver combinations for which the "backend" tests
repeatedly run; as these tests are more oriented towards
basic dialect interaction, add a new "sparse" backend option
that will run the tests only once per base dialect.

Change-Id: I312aa0332d7ec1ff4e2faa15f6b189d6f0f68393
(cherry picked from commit 0ad64da397)
2019-06-20 18:09:37 -04:00
Mike Bayer 542f2831bb Version 1.3.6 placeholder 2019-06-17 14:15:16 -04:00
Mike Bayer 14bf5d73a2 - 1.3.5 rel_1_3_5 2019-06-17 13:25:51 -04:00
Emile Caron 63679c0e4a Fix typo in documentation examples
(cherry picked from commit 1225370714)
2019-06-17 11:32:35 -04:00
mike bayer 927321c305 Merge "Remove unused "time_func"" into rel_1_3 2019-06-17 14:49:02 +00:00
Mike Bayer 844bedd8fa Remove unused "time_func"
This compat name is not used and is also referring to a
deprecated API for the win32 case.

Fixes: #4731
Change-Id: I0f2b07347c15455b58c27e29a19fb55e159f332a
(cherry picked from commit 0fff647a8f)
2019-06-17 09:17:29 -04:00
Eli Collins 8c826331a5 PostgreSQL now reflects per-column sort order on indexes.
Added support for column sorting flags when reflecting indexes for
PostgreSQL, including ASC, DESC, NULLSFIRST, NULLSLAST.  Also adds this
facility to the reflection system in general which can be applied to other
dialects in future releases.  Pull request courtesy Eli Collins.

Fixes: #4717
Closes: #4725
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4725
Pull-request-sha: 3cbb067bd4

Change-Id: I8b0617d68580cfe4ff79d758a077263f33e852c2
(cherry picked from commit b4be7ceb86)
2019-06-17 09:04:34 -04:00
mike bayer ee8d01d797 Merge "Turn off the is_literal flag when proxying literal_column() to Label" into rel_1_3 2019-06-17 01:57:44 +00:00
Mike Bayer be206b7916 Turn off the is_literal flag when proxying literal_column() to Label
Fixed a series of quoting issues which all stemmed from the concept of the
:func:`.literal_column` construct, which when being "proxied" through a
subquery to be referred towards by a label that matches its text, the label
would not have quoting rules applied to it, even if the string in the
:class:`.Label` were set up as a :class:`.quoted_name` construct.  Not
applying quoting to the text of the :class:`.Label` is a bug because this
text is strictly a SQL identifier name and not a SQL expression, and the
string should not have quotes embedded into it already unlike the
:func:`.literal_column` which it may be applied towards.   The existing
behavior of a non-labeled :func:`.literal_column` being propagated as is on
the outside of a subquery is maintained in order to help with manual
quoting schemes, although it's not clear if valid SQL can be generated for
such a construct in any case.

Fixes: #4730
Change-Id: I300941f27872fc4298c74a1d1ed65aef1a5cdd82
(cherry picked from commit 009acc95b8)
2019-06-15 21:34:11 -04:00
Mike Bayer b927836a33 Consult is_attrbute flag to determine descriptor; enable for assoc proxy
Fixed bug where the :attr:`.Mapper.all_orm_descriptors` accessor would
return an entry for the :class:`.Mapper` itself under the declarative
``__mapper___`` key, when this is not a descriptor.  The ``.is_attribute``
flag that's present on all :class:`.InspectionAttr` objects is now
consulted, which has also been modified to be ``True`` for an association
proxy, as it was erroneously set to False for this object.

Fixes: #4729
Change-Id: Ia02388cc25d004e32d337140b62a587f3e5a0b7b
(cherry picked from commit 79d07c9abc)
2019-06-14 22:47:01 -04:00
Mike Bayer 61a7413514 Run PK/FK sync for multi-level inheritance w/ no intermediary update
Also fix DetectKeySwitch for intermediary class relationship

Fixed a series of related bugs regarding joined table inheritance more than
two levels deep, in conjunction with modification to primary key values,
where those primary key columns are also linked together in a foreign key
relationship as is typical for joined table inheritance.  The intermediary
table in a  three-level inheritance hierachy will now get its UPDATE if
only the primary key value has changed and passive_updates=False (e.g.
foreign key constraints not being enforced), whereas before it would be
skipped; similarly, with passive_updates=True (e.g. ON UPDATE  CASCADE in
effect), the third-level table will not receive an UPDATE statement as was
the case earlier which would fail since CASCADE already modified it.   In a
related issue, a relationship linked to a three-level inheritance hierarchy
on the primary key of an intermediary table of a joined-inheritance
hierarchy will also correctly have its foreign key column updated when the
parent object's primary key is modified, even if that parent object is a
subclass of the linked parent class, whereas before these classes would
not be counted.

Fixes: #4723
Change-Id: Idc408ead67702068e64d583a15149dd4beeefc24
(cherry picked from commit 3f7840c2ad)
2019-06-12 14:01:01 -04:00