Commit Graph

6142 Commits

Author SHA1 Message Date
mollardthomas cf609c19bc Add support for filtered indexes for mssql dialect 2019-05-03 14:46:50 +02:00
Mike Bayer ae14861a31 Make the GenericFunction registry fully case insensitive
Registered function names based on :class:`.GenericFunction` are now
retrieved in a case-insensitive fashion in all cases, removing the
deprecation logic from 1.3 which temporarily allowed multiple
:class:`.GenericFunction` objects to exist with differing cases.   A
:class:`.GenericFunction` that replaces another on the same name whether or
not it's case sensitive emits a warning before replacing the object.

Fixes: #4649
Change-Id: I265ae19833132db07ed5b5ae40c4d24f659b1ab3
2019-04-30 14:01:52 -04:00
Adrien Berchet a10a4ea124 Add case insensitivity feature to GenericFunction.
The :class:`.GenericFunction` namespace is being migrated so that function
names are looked up in a case-insensitive manner, as SQL  functions do not
collide on case sensitive differences nor is this something which would
occur with user-defined functions or stored procedures.   Lookups for
functions declared with :class:`.GenericFunction` now use a case
insensitive scheme,  however a deprecation case is supported which allows
two or more :class:`.GenericFunction` objects with the same name of
different cases to exist, which will cause case sensitive lookups to occur
for that particular name, while emitting a warning at function registration
time.  Thanks to Adrien Berchet for a lot of work on this complicated
feature.

Fixes: #4569
Closes: #4570
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4570
Pull-request-sha: 37d4f3322b

Change-Id: Ief07c6eb55bf398f6aad85b60ef13ee6d1173109
2019-04-29 17:24:32 -04:00
mike bayer 6486530405 Merge "Add _cache_key implementation." 2019-04-29 18:53:43 +00:00
mike bayer 7a80f64503 Merge "Reimplement .compare() in terms of a visitor" 2019-04-29 18:52:03 +00:00
Mike Bayer 08da8115a6 Add _cache_key implementation.
This leverages the work started in #4336 to allow ClauseElement
structures to be cachable based on structure, not just identity.

Change-Id: Ia99ddeb5353496dd7d61243245685f02b98d8100
2019-04-29 12:45:45 -04:00
Mike Bayer 0995220750 Reimplement .compare() in terms of a visitor
Reworked the :meth:`.ClauseElement.compare` methods in terms of a new
visitor-based approach, and additionally added test coverage ensuring that
all :class:`.ClauseElement` subclasses can be accurately compared
against each other in terms of structure.   Structural comparison
capability is used to a small degree within the ORM currently, however
it also may form the basis for new caching features.

Fixes: #4336
Change-Id: I581b667d8e1642a6c27165cc9f4aded1c66effc6
2019-04-29 11:54:25 -04:00
mike bayer a3145cffe2 Merge "Warn on merge of already-pending object" 2019-04-28 18:43:37 +00:00
Mike Bayer 23a1c60982 Warn on merge of already-pending object
A warning is now emitted for the case where a transient object is being
merged into the session with :meth:`.Session.merge` when that object is
already transient in the :class:`.Session`.   This warns for the case where
the object would normally be double-inserted.

Fixes: #4647
Change-Id: Ie5223a59a2856664bf283017e962caf8c4230536
2019-04-28 12:44:00 -04:00
mike bayer 0ee9d61e87 Merge "Add additional parsing to extract the "MariaDB" keyword from version string" 2019-04-28 03:16:51 +00:00
Mike Bayer 95dd8768d4 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
2019-04-24 13:11:07 -05:00
Mike Bayer e9737a9d9b negate True/False separately from other elements
Fixed issue where double negation of a boolean column wouldn't reset
the "NOT" operator.

Fixes: #4618
Change-Id: Ica280a0d6b5b0870aa2d05c4d059a1e559e6b12a
(cherry picked from commit 18f25f50353d9736e6638266585b2cb3ef7b0ea4)
2019-04-18 13:41:10 -04:00
Mike Bayer 17413bbf10 Black updates
Updating for a few black adjustments

Change-Id: I9c8abadd1ccd6173e6d68dd62f14cec208cc304a
2019-04-11 14:23:29 -04:00
mike bayer 53c65ed93a Merge "Don't use and_() inside of Query.filter_by" 2019-04-11 01:00:19 +00:00
Mike Bayer 36949938e8 Don't use and_() inside of Query.filter_by
Adjusted the :meth:`.Query.filter_by` method to not call :func:`.and()`
internally against multiple criteria, instead passing it off to
:meth:`.Query.filter` as a series of criteria, instead of a single criteria.
This allows :meth:`.Query.filter_by` to defer to :meth:`.Query.filter`'s
treatment of variable numbers of clauses, including the case where the list
is empty.  In this case, the :class:`.Query` object will not have a
``.whereclause``, which allows subsequent "no whereclause" methods like
:meth:`.Query.select_from` to behave consistently.

Fixes: #4606
Change-Id: Ifc8cdbf13accca2236068ef70114a7c35ab159ff
2019-04-10 11:56:49 -04:00
mike bayer deed49489b Merge "Add __reduce_ex__ to MutableList; add compat for older pickles" 2019-04-10 01:14:57 +00:00
Mike Bayer 21099479da Add __reduce_ex__ to MutableList; add compat for older pickles
Fixed bug where using ``copy.copy()`` or ``copy.deepcopy()`` on
:class:`.MutableList` would cause the items within the list to be
duplicated, due to an inconsistency in how Python pickle and copy both make
use of ``__getstate__()`` and ``__setstate__()`` regarding lists.  In order
to resolve, a ``__reduce_ex__`` method had to be added to
:class:`.MutableList`.  In order to maintain backwards compatibility with
existing pickles based on ``__getstate__()``, the ``__setstate__()`` method
remains as well; the test suite asserts that pickles made against the old
version of the class can still be deserialized by the pickle module.

Also modified sqlalchemy.testing.util.picklers to return picklers all the way through
pickle.HIGHEST_PROTOCOL.

Fixes: #4603
Change-Id: I7f78b9cfb89d59a706248536c553dc5e1d987b88
2019-04-09 21:13:56 -04:00
Mike Bayer c29b352d56 Propagate query-arg-only URL to psycopg2; don't send blank host
Fixed regression from release 1.3.2 caused by 🎫`4562` where a URL
that contained only a query string and no hostname, such as for the
purposes of specifying a service file with connection information, would no
longer be propagated to psycopg2 properly.   The change in 🎫`4562`
has been adjusted to further suit psycopg2's exact requirements, which is
that if there are any connection parameters whatsoever, the "dsn" parameter
is no longer required, so in this case the query string parameters are
passed alone.

Fixes: #4601
Change-Id: Ic29a8b77bcf50ee996968bab25aaac7ae4bfc26f
2019-04-09 17:40:14 -04:00
Matt Lewellyn 97d4d15fde MSSQL: only compile ORDER BY if it will be rendered
Fixed issue in SQL Server dialect where if a bound parameter were present in
an ORDER BY expression that would ultimately not be rendered in the SQL
Server version of the statement, the parameters would still be part of the
execution parameters, leading to DBAPI-level errors.  Pull request courtesy
Matt Lewellyn.

Fixes: #4587
Closes: #4588
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4588
Pull-request-sha: 2992a473e0

Change-Id: Ie709aefdb1babf810bb81526289448f8cc7a4cb1
2019-04-04 10:52:29 -04:00
mike bayer b90f9b5f36 Merge "Restore use_threadlocal equivalent behavior to SingletonThreadPool" 2019-04-03 21:15:07 +00:00
Mike Bayer a326869cf9 Restore use_threadlocal equivalent behavior to SingletonThreadPool
Fixed behavioral regression as a result of deprecating the "use_threadlocal"
flag for :class:`.Pool`, where the :class:`.SingletonThreadPool` no longer
makes use of this option which causes the "rollback on return" logic to take
place when the same :class:`.Engine` is used multiple times in the context
of a transaction to connect or implicitly execute, thereby cancelling the
transaction.   While this is not the recommended way to work with engines
and connections, it is nonetheless a confusing behavioral change as when
using :class:`.SingletonThreadPool`, the transaction should stay open
regardless of what else is done with the same engine in the same thread.
The ``use_threadlocal`` flag remains deprecated however the
:class:`.SingletonThreadPool` now implements its own version of the same
logic.

Fixes: #4585
Change-Id: I906293f2d0a5d14ed46cd9e64305a6481505a5a3
2019-04-03 10:12:57 -04:00
Mike Bayer 25a42e93f4 Fold entities into existing joins when resolving FROM ambiguity
Fixed 1.3 regression in new "ambiguous FROMs" query logic introduced in
:ref:`change_4365` where a :class:`.Query` that explicitly places an entity
in the FROM clause with :meth:`.Query.select_from` and also joins to it
using :meth:`.Query.join` would later cause an "ambiguous FROM" error if
that entity were used in additional joins, as the entity appears twice in
the "from" list of the :class:`.Query`.  The fix resolves this ambiguity by
folding the standalone entity into the join that it's already a part of in
the same way that ultimately happens when the SELECT statement is rendered.

Fixes: #4584
Change-Id: Ic62ca09c6d329695b21ed4f1be8621edcbb18e19
2019-04-02 23:42:36 -04:00
mike bayer 9168aae5e7 Merge "Refine ambiguous access for unknown attribute types" 2019-03-27 17:38:02 +00:00
mike bayer 1f6871ef0e Merge "Test double colons without escaping in text()" 2019-03-26 19:34:23 +00:00
Mike Bayer 51f81d00dc Refine ambiguous access for unknown attribute types
Restored instance-level support for plain Python descriptors, e.g.
``@property`` objects, in conjunction with association proxies, in that if
the proxied object is not within ORM scope at all, it gets classified as
"ambiguous" but is proxed directly.  For class level access, a basic class
level``__get__()`` now returns the
:class:`.AmbiguousAssociationProxyInstance` directly, rather than raising
its exception, which is the closest approximation to the previous behavior
that returned the :class:`.AssociationProxy` itself that's possible.  Also
improved the stringification of these objects to be more descriptive of
current state.

Fixes: #4574
Change-Id: I787a22806b5530c146ae6ee66b588e5b191ae689
2019-03-26 15:17:48 -04:00
Mike Bayer c8fca639c9 Test double colons without escaping in text()
Apparently the BIND_PARAMS regex passes over double colons,
it just doesn't accommodate for a bound parameter in that case.
add this use case to current tests as people can be relying upon it.

Change-Id: I6555621b1bb05d09b17428f4b4094ff7b219b460
2019-03-26 13:29:57 -04:00
mike bayer 47ee0e2e0f Merge "Fix boolean check in new path comparison logic" 2019-03-25 19:09:58 +00:00
Mike Bayer da04aa577b Fix boolean check in new path comparison logic
Fixed regression where a new error message that was supposed to raise when
attempting to link a relationship option to an AliasedClass without using
:meth:`.PropComparator.of_type` would instead raise an ``AttributeError``.
Note that in 1.3, it is no longer valid to create an option path from a
plain mapper relationship to an :class:`.AliasedClass` without using
:meth:`.PropComparator.of_type`.

Fixes: #4566
Change-Id: Ic547a1c8408e41aec66ef9644aac7f76f50dd064
2019-03-24 12:35:53 -04:00
Julian Mehnle a31da95e00 Support DNS-less connections for psycopg2
Added support for parameter-less connection URLs for the psycopg2 dialect,
meaning, the URL can be passed to :func:`.create_engine` as
``"postgresql+psycopg2://"`` with no additional arguments to indicate an
empty DSN passed to libpq, which indicates to connect to "localhost" with
no username, password, or database given. Pull request courtesy Julian
Mehnle.

Fixes: #4562
Closes: #4563
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4563
Pull-request-sha: 8a05c96944

Change-Id: Ib6fca3c3c9eebeaf590d7f7fb0bc8cd4b6e4a55a
2019-03-24 12:03:28 -04:00
raylu 8acbc2624f Expand joins when calculating PostgreSQL "WITH FOR UPDATE OF"
Modified the :paramref:`.Select.with_for_update.of` parameter so that if a
join or other composed selectable is passed, the individual :class:`.Table`
objects will be filtered from it, allowing one to pass a join() object to
the parameter, as occurs normally when using joined table inheritance with
the ORM.  Pull request courtesy Raymond Lu.

Fixes: #4550
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Closes: #4551
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4551
Pull-request-sha: 452da77d15

Change-Id: If4b7c231f7b71190d7245543959fb5c3351125a1
2019-03-21 10:25:29 -04:00
mike bayer 4aadcca993 Merge "Clone internals for Select._correlate_except collection as well as _correlate" 2019-03-11 14:49:23 +00:00
Mike Bayer 25fc9562f0 Clone internals for Select._correlate_except collection as well as _correlate
Fixed bug where use of :func:`.with_polymorphic` or other aliased construct
would not properly adapt when the aliased target were used as the
:meth:`.Select.correlate_except` target of a subquery used inside of a
:func:`.column_property`.  This required a fix to the clause adaption
mechanics to properly handle a selectable that shows up in the "correlate
except" list, in a similar manner as which occurs for selectables that show
up in the "correlate" list.  This is ultimately a fairly fundamental bug
that has lasted for a long time but it is hard to come across it.

Fixes: #4537
Change-Id: Ibb97d4eea18b3c452aad519dd14919bfb84d422f
2019-03-10 23:44:08 -04:00
Mike Bayer cbc31716c2 Commit transaction after SNAPSHOT isolation change
A commit() is emitted after an isolation level change to SNAPSHOT, as both
pyodbc and pymssql open an implicit transaction which blocks subsequent SQL
from being emitted in the current transaction.

Fixes: #4536
Change-Id: If3ba70f495bce2a35a873a3a72d1b30406e678c8
2019-03-08 23:45:25 -05:00
mike bayer 2160b7e652 Merge "Ensure association proxy works over synonym" 2019-03-06 16:38:49 +00:00
mike bayer 0137b75136 Merge "Ensure scale param not sent to float types" 2019-03-06 15:47:01 +00:00
Mike Bayer b78f460465 Ensure association proxy works over synonym
Fixed regression where an association proxy linked to a synonym would no
longer work, both at instance level and at class level.

Fixes: #4522
Change-Id: I949079229ef87c12736c362df35444f6e30c8038
2019-03-06 10:16:49 -05:00
Mike Bayer cb968b6dcd Loosen SingletonThreadPoolTest
This test is non-critical as the SingletonThreadPool is
not production-level robust under multithreaded scenarios in
any case.

Fixes: #4527
Change-Id: Ie19ebd69438c97b2d8adb571f8f1b2c56894f7fb
2019-03-06 09:09:38 -05:00
Mike Bayer 2a2011389a Ensure scale param not sent to float types
Fixed regression in SQL Server reflection due to 🎫`4393` where the
removal of open-ended ``**kw`` from the :class:`.Float` datatype caused
reflection of this type to fail due to a "scale" argument being passed.

Fixes: #4525
Change-Id: Ief8bb535778055eff2ab0d71660f81e3676390a1
2019-03-06 09:06:04 -05:00
Mike Bayer 201c4a60e4 run a black run
fix some pep8s that snuck in

Change-Id: Ied282007df30a52d232b1ba88659f2a123ff380f
2019-03-05 20:29:05 -05:00
mike bayer f24659b72b Merge "Add port comparison in __eq__() and __ne__() method to URL" 2019-03-04 15:45:53 +00:00
Sanjana 9268c320bf Add port comparison in __eq__() and __ne__() method to URL
Comparing two objects of :class:`.URL` using ``__eq__()`` did not take port
number into consideration, two objects differing only by port number were
considered equal. Port comparison is now added in ``__eq__()`` method of
:class:`.URL`, objects differing by port number are now not equal.
Additionally, ``__ne__()`` was not implemented for :class:`.URL` which
caused unexpected result when ``!=`` was used in Python2, since there are no
implied relationships among the comparison operators in Python2.

Fixes: #4406
Closes: #4515
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4515
Pull-request-sha: 0f15b805f0

Change-Id: Iba7d224f1282dc3f4b884d1a746f2d46669f551e
2019-02-28 14:34:52 -05:00
Mike Bayer a690ec0824 Add resolve_fks=False option for reflection
Added new parameters :paramref:`.Table.resolve_fks` and
:paramref:`.MetaData.reflect.resolve_fks` which when set to False will
disable the automatic reflection of related tables encountered in
:class:`.ForeignKey` objects, which can both reduce SQL overhead for omitted
tables as well as avoid tables that can't be reflected for database-specific
reasons.  Two :class:`.Table` objects present in the same :class:`.MetaData`
collection can still refer to each other even if the reflection of the two
tables occurred separately.

Fixes: #4517
Change-Id: I623baed42042a16c5109e4c8af6b2f64d2d00f95
2019-02-28 13:49:09 -05:00
mike bayer 53c7fc4690 Merge "Add test to as_interface when no cls or methods" 2019-02-22 00:33:55 +00:00
mike bayer 0cdc89c276 Merge "Prevent __init__ from being called for Alias, subclasses" 2019-02-22 00:33:31 +00:00
Toni Karppi 40401d7933 Add test to as_interface when no cls or methods
Fixes #4511

### Description
The `as_interface` function requires that an argument be provided for at least one of the parameters `cls` or `methods`. There was no test that tested the case when neither of these arguments were provided.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [ ] A documentation / typographical error fix
	- Good to go, no issue or tests are needed
- [x] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #4512
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4512
Pull-request-sha: 156f6af95e

Change-Id: Ifa23dbe1dbe9a824fe680e4947b81c96a50c133f
2019-02-21 14:22:48 -05:00
mike bayer eed102f465 Merge "Add support for key-word based get()" 2019-02-21 19:19:49 +00:00
Mike Bayer 4ca3092c0a Prevent __init__ from being called for Alias, subclasses
The :class:`.Alias` class and related subclasses :class:`.CTE`,
:class:`.Lateral` and :class:`.TableSample` have been reworked so that it is
not possible for a user to construct the objects directly.  These constructs
require that the standalone construction function or selectable-bound method
be used to instantiate new objects.

Fixes: #4509
Change-Id: I74ae4786cb3ae625dab33b00bfd6bdc4e1219139
2019-02-21 11:18:19 -05:00
mike bayer 0a1c640531 Merge "Include newlines in StatementError formatting" 2019-02-21 15:52:29 +00:00
Nate Clark 8f318692d4 Include newlines in StatementError formatting
Revised the formatting for :class:`.StatementError` when stringified. Each
error detail is broken up over multiple newlines instead of spaced out on a
single line.  Additionally, the SQL representation now stringifies the SQL
statement rather than using ``repr()``, so that newlines are rendered as is.
Pull request courtesy Nate Clark.

Fixes: #4500

Closes: #4501
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4501
Pull-request-sha: 60cc0ee68d

Change-Id: I79d8418b7495e5691c9a56f41e79495c26a967ff
2019-02-20 18:56:47 -05:00
sanjana c89a93e953 Add support for key-word based get()
The :meth:`.Query.get` method can now accept a dictionary of attribute keys
and values as a means of indicating the primary key value to load; is
particularly useful for composite primary keys.  Pull request courtesy
Sanjana S.

Fixes: #4316

Closes: #4505
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4505
Pull-request-sha: cfa8297ad2

Change-Id: Ib19e7d51599a36f4878119c2f801c5c694793422
2019-02-20 17:08:34 -05:00