]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/log
thirdparty/sqlalchemy/sqlalchemy.git
5 years agoresolves #5333 typo correction 'explcit' should be 'explicit'. 5410/head
RamonWill [Sat, 4 Jul 2020 13:30:19 +0000 (14:30 +0100)] 
resolves #5333 typo correction 'explcit' should be 'explicit'.

5 years agoMerge "Propose black py27 + py35 mode for the rest of Py2K"
mike bayer [Fri, 19 Jun 2020 21:44:18 +0000 (21:44 +0000)] 
Merge "Propose black py27 + py35 mode for the rest of Py2K"

5 years agoMerge "Added reflection method :meth:`.Inspector.get_sequence_names`"
mike bayer [Fri, 19 Jun 2020 21:00:37 +0000 (21:00 +0000)] 
Merge "Added reflection method :meth:`.Inspector.get_sequence_names`"

5 years agoMerge "Move most setup options to setup.cfg"
mike bayer [Fri, 19 Jun 2020 20:55:46 +0000 (20:55 +0000)] 
Merge "Move most setup options to setup.cfg"

5 years agoMove most setup options to setup.cfg
Mike Bayer [Thu, 18 Jun 2020 22:45:40 +0000 (18:45 -0400)] 
Move most setup options to setup.cfg

Installation has been modernized to use setup.cfg for most package
metadata.

Fixes: #5404
Change-Id: Id59c0c4e7f81eca89999d1f1f8b03c89835a09d1

5 years agoMerge "perf tweaks"
mike bayer [Fri, 19 Jun 2020 15:21:39 +0000 (15:21 +0000)] 
Merge "perf tweaks"

5 years agoAdd note indicating order of join() calls are important
Mike Bayer [Fri, 19 Jun 2020 15:06:08 +0000 (11:06 -0400)] 
Add note indicating order of join() calls are important

Fixes: #5406
Change-Id: I186792b32bd156d5ddf256dcd018af32ad5b515e

5 years agoPropose black py27 + py35 mode for the rest of Py2K
Mike Bayer [Fri, 19 Jun 2020 14:25:42 +0000 (10:25 -0400)] 
Propose black py27 + py35 mode for the rest of Py2K

py27 mode produces one failure for flake8 which is the
space added between exec and parenthesis.  however apparently
we can add multiple versions to target-versions which allows
the exec() calls to come out in python 3 style.

The issue we want to improve is issues of trailing
commas being added.  I'm not really able to get black to
consistently add or remove these trailing commas in any
case no matter what I set target-version towards.

Change-Id: Iceb9e9aeb5f5e0d317fb877ef06eca0290997fe4

5 years agoperf tweaks
Mike Bayer [Fri, 19 Jun 2020 04:32:00 +0000 (00:32 -0400)] 
perf tweaks

- avoid abc checks in distill_20
- ColumnEntity subclasses are unique to their compile state and
have no querycontext specific state.  They can do a simple memoize of their
fetch_column without using attributes, and they can memoize their
_getter() too so that it goes into the cache, just like
instance_processor() does.
- unify ORMColumnEntity and RawColumnEntity for the row processor part,
add some test coverage for the case where it is used in a from_statement
- do a faster generate if there are no memoized entries
- query._params is always immutabledict
Change-Id: I1e2dfe607a1749b5b434fc11f9348ee631501dfa

5 years agoWarn when transaction context manager ends on inactive transaction
Mike Bayer [Fri, 12 Jun 2020 17:09:15 +0000 (13:09 -0400)] 
Warn when transaction context manager ends on inactive transaction

if .rollback() or .commit() is called inside the transaction
context manager, the transaction object is deactivated.
the context manager continues but will not be able to correctly
fulfill it's closing state.  Ensure a warning is emitted when
this happens.

Change-Id: I8fc3a73f7c21575dda5bcbd6fb74ddb679771630

5 years agoAdd version token to error URL
Mike Bayer [Thu, 11 Jun 2020 18:31:57 +0000 (14:31 -0400)] 
Add version token to error URL

the sqlalche.me redirector now supports the numerical version
code in the URL, e.g. /13/, /14/, /20/, etc., so that we can
redirect to the error codes for the appropriate version
of SQLAlchemy in use without going through the catch-all "latest"
link.   If a particular version of the docs is no longer on the
site, the redirect will revert to falling through the "latest"
link (which ultimately lands on the current release version,
/13/ at the time of this writing).

Change-Id: I3bb463fd6fb6c8767c95a57f3699aba715a9a72d

5 years agoAdd 'exists' to SQLite's reserved keywords
Thodoris Sotiropoulos [Thu, 11 Jun 2020 14:50:41 +0000 (10:50 -0400)] 
Add 'exists' to SQLite's reserved keywords

Added "exists" to the list of reserved words for SQLite so that this word
will be quoted when used as a label or column name. Pull request courtesy
Thodoris Sotiropoulos.

Fixes: #5395
Closes: #5396
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5396
Pull-request-sha: 5608317a38db7b63115e3b467d182a3e5cc31580

Change-Id: Ia4769de2dec159dcf282eb4b30c11560da51a5c7

5 years agoMerge "Add documentation regarding row constructo in PostgreSQL"
mike bayer [Thu, 11 Jun 2020 03:14:46 +0000 (03:14 +0000)] 
Merge "Add documentation regarding row constructo in PostgreSQL"

5 years agoMerge "Improve ``Rendering Bound Parameters Inline`` documentation"
mike bayer [Thu, 11 Jun 2020 03:13:28 +0000 (03:13 +0000)] 
Merge "Improve ``Rendering Bound Parameters Inline`` documentation"

5 years agoMerge "Turn on caching everywhere, add logging"
mike bayer [Wed, 10 Jun 2020 22:03:37 +0000 (22:03 +0000)] 
Merge "Turn on caching everywhere, add logging"

5 years agoTurn on caching everywhere, add logging
Mike Bayer [Sun, 7 Jun 2020 00:40:43 +0000 (20:40 -0400)] 
Turn on caching everywhere, add logging

A variety of caching issues found by running
all tests with statement caching turned on.

The cache system now has a more conservative approach where
any subclass of a SQL element will by default invalidate
the cache key unless it adds the flag inherit_cache=True
at the class level, or if it implements its own caching.

Add working caching to a few elements that were
omitted previously; fix some caching implementations
to suit lesser used edge cases such as json casts
and array slices.

Refine the way BaseCursorResult and CursorMetaData
interact with caching; to suit cases like Alembic
modifying table structures, don't cache the
cursor metadata if it were created against a
cursor.description using non-positional matching,
e.g. "select *".   if a table re-ordered its columns
or added/removed, now that data is obsolete.

Additionally we have to adapt the cursor metadata
_keymap regardless of if we just processed
cursor.description, because if we ran against
a cached SQLCompiler we won't have the right
columns in _keymap.

Other refinements to how and when we do this
adaption as some weird cases
were exposed in the Postgresql dialect,
a text() construct that names just one column that
is not actually in the statement.   Fixed that
also as it looks like a cut-and-paste artifact
that doesn't actually affect anything.

Various issues with re-use of compiled result maps
and cursor metadata in conjunction with tables being
changed, such as change in order of columns.

mappers can be cleared but the class remains, meaning
a mapper has to use itself as the cache key not the class.

lots of bound parameter / literal issues, due to Alembic
creating a straight subclass of bindparam that renders
inline directly.   While we can update Alembic to not
do this, we have to assume other people might be doing
this, so bindparam() implements the inherit_cache=True
logic as well that was a bit involved.

turn on cache stats in logging.

Includes a fix to subqueryloader which moves all setup to
the create_row_processor() phase and elminates any storage
within the compiled context.   This includes some changes
to create_row_processor() signature and a revising of the
technique used to determine if the loader can participate
in polymorphic queries, which is also applied to
selectinloading.

DML update.values() and ordered_values() now coerces the
keys as we have tests that pass an arbitrary class here
which only includes __clause_element__(), so the
key can't be cached unless it is coerced.  this in turn
changed how composite attributes support bulk update
to use the standard approach of ClauseElement with
annotations that are parsed in the ORM context.

memory profiling successfully caught that the Session
from Query was getting passed into _statement_20()
so that was a big win for that test suite.

Apparently Compiler had .execute() and .scalar() methods
stuck on it, these date back to version 0.4 and there
was a single test in the PostgreSQL dialect tests
that exercised it for no apparent reason.   Removed
these methods as well as the concept of a Compiler
holding onto a "bind".

Fixes: #5386
Change-Id: I990b43aab96b42665af1b2187ad6020bee778784

5 years agoMerge "updated historical terms with modern equivalents"
mike bayer [Tue, 9 Jun 2020 16:28:00 +0000 (16:28 +0000)] 
Merge "updated historical terms with modern equivalents"

5 years agoFix capitalization typos in engines.rst 5385/head
Abraham Sangha [Mon, 8 Jun 2020 16:17:09 +0000 (10:17 -0600)] 
Fix capitalization typos in engines.rst

5 years agoConvert bulk update/delete to new execution model
Mike Bayer [Wed, 3 Jun 2020 21:38:35 +0000 (17:38 -0400)] 
Convert bulk update/delete to new execution model

This reorganizes the BulkUD model in sqlalchemy.orm.persistence
to be based on the CompileState concept and to allow plain
update() / delete() to be passed to session.execute() where
the ORM synchronize session logic will take place.
Also gets "synchronize_session='fetch'" working with horizontal
sharding.

Adding a few more result.scalar_one() types of methods
as scalar_one() seems like what is normally desired.

Fixes: #5160
Change-Id: I8001ebdad089da34119eb459709731ba6c0ba975

5 years agoupdated historical terms with modern equivalents
jonathan vanasco [Sat, 6 Jun 2020 01:58:23 +0000 (21:58 -0400)] 
updated historical terms with modern equivalents

### Description
There were a few remnant uses of master/slave in the code and docs. The project previously made a decision to move away from them to use modern and inclusive terminology.

This PR does not cover a bug or necessitate a documented entry into the changelog, so an issue ticket was not created.

### Checklist
This pull request is:

- [x] A documentation / typographical error fix
- [x] A short code fix
- [ ] A new feature implementation

Closes: #5381
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5381
Pull-request-sha: 92597e83d0e1e18960dbb39b604b313e7a1cbb30

Change-Id: I1fb34fe5ab6c19fd7360568d7b51cdea9d271b3b

5 years agoFix connection string escaping for mssql+pyodbc
Gord Thompson [Thu, 4 Jun 2020 18:38:13 +0000 (12:38 -0600)] 
Fix connection string escaping for mssql+pyodbc

Fixes: #5373
Change-Id: Ia41e8f1ef8644c54d23ebfdf3f909c785adf0fb0

5 years agoImprove ``Rendering Bound Parameters Inline`` documentation
Federico Caselli [Thu, 4 Jun 2020 17:53:29 +0000 (19:53 +0200)] 
Improve ``Rendering Bound Parameters Inline`` documentation

This is mainly to make this section more discoverable by users

Change-Id: I58ba19e4a9ae85b227e5b5553ba5c30c01f3e005

5 years agoDocument that type_coerce does not currently imply parenthesization
Mike Bayer [Thu, 4 Jun 2020 17:28:21 +0000 (13:28 -0400)] 
Document that type_coerce does not currently imply parenthesization

We've had a few issues where the current solution
is to use the self_group() method, so document that as
the current approach for the parenthesization use case.
Whether or not type_coerce() is changed later, this is
how it works at the moment.

Fixes: #5375
Change-Id: I97414762a87ec8f1fd1adc1b6be5a52e576814ca
References: #5344

5 years agoMerge "Folds two identical exception handlers into a single one"
mike bayer [Wed, 3 Jun 2020 22:23:32 +0000 (22:23 +0000)] 
Merge "Folds two identical exception handlers into a single one"

5 years agoMerge "Default create_constraint to False"
mike bayer [Wed, 3 Jun 2020 22:22:37 +0000 (22:22 +0000)] 
Merge "Default create_constraint to False"

5 years agoDefault create_constraint to False
Mike Bayer [Tue, 2 Jun 2020 18:21:03 +0000 (14:21 -0400)] 
Default create_constraint to False

The :paramref:`.Enum.create_constraint` and
:paramref:`.Boolean.create_constraint` parameters now default to False,
indicating when a so-called "non-native" version of these two datatypes is
created, a CHECK constraint will not be generated by default.   These CHECK
constraints present schema-management maintenance complexities that should
be opted in to, rather than being turned on by default.

Fixes: #5367
Change-Id: I0a3fb608ce32143fa757546cc17ba2013e93272a

5 years agoAdded reflection method :meth:`.Inspector.get_sequence_names`
Federico Caselli [Mon, 13 Apr 2020 10:16:21 +0000 (12:16 +0200)] 
Added reflection method :meth:`.Inspector.get_sequence_names`

Added new reflection method :meth:`.Inspector.get_sequence_names` which
returns all the sequences defined. Support for this method has been added
to the backend that support :class:`.Sequence`: PostgreSql, Oracle,
MSSQL and MariaDB >= 10.3.

Fixes: #2056
Change-Id: I0949696a39aa28c849edf2504779241f7443778a

5 years agoFolds two identical exception handlers into a single one
Elmer de Looff [Wed, 3 Jun 2020 16:24:41 +0000 (12:24 -0400)] 
Folds two identical exception handlers into a single one

Fixes a `TODO` that searches for py2/3 compatible syntax to match multiple exception types.

### Description

Merges the two exception clauses using the syntax that exists for both Python 2 and 3 as per the exception handling tutorials ([Python 2](https://docs.python.org/2/tutorial/errors.html#handling-exceptions), [Python 3](https://docs.python.org/3/tutorial/errors.html#handling-exceptions))

### Checklist

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: #5325
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5325
Pull-request-sha: d0835511e5509fb368a2193ebe4ecbbe3504b129

Change-Id: If3a8854e4de023e0ec68ae8649d24af9412f0717

5 years agoInline a few ORM arguments, others
Mike Bayer [Wed, 3 Jun 2020 13:50:04 +0000 (09:50 -0400)] 
Inline a few ORM arguments, others

small changes

Change-Id: Id89a0651196c431d0aaf6935f5a4e7b12dd70c6c

5 years agoMerge "Add default expression to query_expression()"
mike bayer [Tue, 2 Jun 2020 17:56:31 +0000 (17:56 +0000)] 
Merge "Add default expression to query_expression()"

5 years agoMerge "Refine IN and scalar subquery coercions"
mike bayer [Tue, 2 Jun 2020 01:00:19 +0000 (01:00 +0000)] 
Merge "Refine IN and scalar subquery coercions"

5 years agoMark two tests as requiring boolean col expressions
Mike Bayer [Mon, 1 Jun 2020 23:30:49 +0000 (19:30 -0400)] 
Mark two tests as requiring boolean col expressions

fixes CI failures on mssql

Change-Id: Ib9d3102bd7f8f4fb9ac5ac21abbb6a866e1f99cf

5 years agoRefine IN and scalar subquery coercions
Mike Bayer [Mon, 1 Jun 2020 23:11:19 +0000 (19:11 -0400)] 
Refine IN and scalar subquery coercions

Ensure IN emits a warning when it coerces a FromClause
into a select(), however that it continues to allow the
scalar_subquery() coercion to be automatic, particularly
since it's not clear that "col IN (select)" is necessarily
"scalar" in the case of tuples.

Convert the "scalar_subquery()" warning emitted in other
cases to be a warning, rather than a deprecation warning.
I can't imagine taking this coercion out as it is intuitive
and is always going to happen; we just would like to note that
an implicit coercion is occurring.

Fixes: #5369
Change-Id: I748f01f40bc85c64e2776f9b88ef35641fa8fb5c

5 years agoAdd a test / comment about test_orm_query
Mike Bayer [Mon, 1 Jun 2020 20:26:41 +0000 (16:26 -0400)] 
Add a test / comment about test_orm_query

Change-Id: I8d78b3e75127141da177f711fd91216391a3c859

5 years agoMerge "Improve rendering of core statements w/ ORM elements"
mike bayer [Mon, 1 Jun 2020 20:03:28 +0000 (20:03 +0000)] 
Merge "Improve rendering of core statements w/ ORM elements"

5 years agoMerge "Support multiple dotted sections in mssql schema names"
mike bayer [Mon, 1 Jun 2020 19:43:04 +0000 (19:43 +0000)] 
Merge "Support multiple dotted sections in mssql schema names"

5 years agoSupport multiple dotted sections in mssql schema names
Mike Bayer [Mon, 1 Jun 2020 00:34:03 +0000 (20:34 -0400)] 
Support multiple dotted sections in mssql schema names

Refined the logic used by the SQL Server dialect to interpret multi-part
schema names that contain many dots, to not actually lose any dots if the
name does not have bracking or quoting used, and additionally to support a
"dbname" token that has many parts including that it may have multiple,
independently-bracketed sections.

This fix addresses #5364 to some degree but probably does not
resolve it fully.

References: #5364
Fixes: #5366
Change-Id: I460cd74ce443efb35fb63b6864f00c6d81422688

5 years agoMerge "Add support for "real" sequences in mssql"
mike bayer [Mon, 1 Jun 2020 19:20:57 +0000 (19:20 +0000)] 
Merge "Add support for "real" sequences in mssql"

5 years agoAdd default expression to query_expression()
Haoyu Sun [Fri, 29 May 2020 18:31:07 +0000 (14:31 -0400)] 
Add default expression to query_expression()

Added a new parameter :paramref:`_orm.query_expression.default_expr` to the
:func:`_orm.query_expression` construct, which will be appled to queries
automatically if the :func:`_orm.with_expression` option is not used. Pull
request courtesy Haoyu Sun.

Fixes: #5198
Closes: #5354
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5354
Pull-request-sha: 57dd4922a3ae4e5fe56dcc541d85ce42256b38b9

Change-Id: I3400f2c00b58bf161f31c74c579feb9ac0f03356

5 years agoFix is_disconnect false positive for mssql+pyodbc
Gord Thompson [Fri, 29 May 2020 13:20:54 +0000 (07:20 -0600)] 
Fix is_disconnect false positive for mssql+pyodbc

Fixed an issue where the ``is_disconnect`` function in the SQL Server
pyodbc dialect was incorrectly reporting the disconnect state when the
exception messsage had a substring that matched a SQL Server ODBC error
code.

Fixes: #5359
Change-Id: I450c6818405a20f4daee20d58fce2d5ecb33e17f

5 years agoImprove rendering of core statements w/ ORM elements
Mike Bayer [Wed, 29 Apr 2020 23:46:43 +0000 (19:46 -0400)] 
Improve rendering of core statements w/ ORM elements

This patch contains a variety of ORM and expression layer
tweaks to support ORM constructs in select() statements,
without the 1.3.x requiremnt in Query that a full
_compile_context() + new select() is needed in order to
get a working statement object.

Includes such tweaks as the ability to implement
aliased class of an aliased class,
as we are looking to fully support ACs against subqueries,
as well as the ability to access anonymously-labeled
ColumnProperty expressions within subqueries by
naming the ".key" of the label after the property
key.   Some tuning to query.join() as well
as ORMJoin internals to allow things to work more
smoothly.

Change-Id: Id810f485c5f7ed971529489b84694e02a3356d6d

5 years agoMerge "Remove loader option cycle"
mike bayer [Fri, 29 May 2020 21:45:54 +0000 (21:45 +0000)] 
Merge "Remove loader option cycle"

5 years agoadd posargs to pep8
Mike Bayer [Fri, 29 May 2020 20:47:29 +0000 (16:47 -0400)] 
add posargs to pep8

we want to be able to specify --output-file

Change-Id: Ib4e992d47587385a50c35ca915bc5adcb2ca49fa

5 years agoRemove loader option cycle
Mike Bayer [Thu, 28 May 2020 20:14:11 +0000 (16:14 -0400)] 
Remove loader option cycle

removed a reference cycle set up by loader options
due to the attribute dictionary containing Load objects
that reference that dictionary.

Change-Id: Ie3159a084f819ae44ca4992b0dbe094fb69b2fa7

5 years agoAdd support for "real" sequences in mssql
Gord Thompson [Sun, 19 Apr 2020 17:47:19 +0000 (11:47 -0600)] 
Add support for "real" sequences in mssql

Added support for "CREATE SEQUENCE" and full :class:`.Sequence` support for
Microsoft SQL Server.  This removes the deprecated feature of using
:class:`.Sequence` objects to manipulate IDENTITY characteristics which
should now be performed using ``mssql_identity_start`` and
``mssql_identity_increment`` as documented at :ref:`mssql_identity`. The
change includes a new parameter :paramref:`.Sequence.data_type` to
accommodate SQL Server's choice of datatype, which for that backend
includes INTEGER and BIGINT.   The default starting value for SQL Server's
version of :class:`.Sequence` has been set at 1; this default is now
emitted within the CREATE SEQUENCE DDL for all backends.

Fixes: #4235
Fixes: #4633
Change-Id: I6aa55c441e8146c2f002e2e201a7f645e667b916

5 years agoAdd full profile sort, dumping to profile results
Mike Bayer [Thu, 28 May 2020 22:16:32 +0000 (18:16 -0400)] 
Add full profile sort, dumping to profile results

Change-Id: Ib256ae34de15d29ee9a48e3be86073610f8d1a65

5 years agoMerge "callcount reductions and refinement for cached queries"
mike bayer [Thu, 28 May 2020 19:28:35 +0000 (19:28 +0000)] 
Merge "callcount reductions and refinement for cached queries"

5 years agocallcount reductions and refinement for cached queries
Mike Bayer [Tue, 26 May 2020 02:36:44 +0000 (22:36 -0400)] 
callcount reductions and refinement for cached queries

This commit includes that we've removed the "_orm_query"
attribute from compile state as well as query context.
The attribute created reference cycles and also added
method call overhead.    As part of this change,
the interface for ORMExecuteState changes a bit, as well
as the interface for the horizontal sharding extension
which now deprecates the "query_chooser" callable
in favor of "execute_chooser", which receives the contextual
object.  This will also work more nicely when we implement
the new execution path for bulk updates and deletes.

Pre-merge execution options for statement, connection,
arguments all up front in Connection.  that way they
can be passed to the before_execute / after_execute events,
and the ExecutionContext doesn't have to merge as second
time.   Core execute is pretty close to 1.3 now.

baked wasn't using the new one()/first()/one_or_none() methods,
fixed that.

Convert non-buffered cursor strategy to be a stateless
singleton.  inline all the paths by which the strategy
gets chosen, oracle and SQL Server dialects make use of the
already-invoked post_exec() hook to establish the alternate
strategies, and this is actually much nicer than it was before.

Add caching to mapper instance processor for getters.

Identified a reference cycle per query that was showing
up as a lot of gc cleanup, fixed that.

After all that, performance not budging much.  Even
test_baked_query now runs with significantly fewer function
calls than 1.3, still 40% slower.

Basically something about the new patterns just makes
this slower and while I've walked a whole bunch of them
back, it hardly makes a dent.  that said, the performance
issues are relatively small, in the 20-40% time increase
range, and the new caching feature
does provide for regular ORM and Core queries that
are cached, and they are faster than non-cached.

Change-Id: I7b0b0d8ca550c05f79e82f75cd8eff0bbfade053

5 years agoMerge "SYBASE: Added offset support"
mike bayer [Thu, 28 May 2020 16:42:20 +0000 (16:42 +0000)] 
Merge "SYBASE: Added offset support"

5 years agoFix 'email_address' being typoed as 'email_addres' in two places
Mark Amery [Thu, 28 May 2020 12:57:26 +0000 (08:57 -0400)] 
Fix 'email_address' being typoed as 'email_addres' in two places

### Description
Fixes a typo that coincidentally occurs in a couple of different places - once in the docs, and another time in a test, where it was presumably neutering one of the test's assertions by making it always pass.

### 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:

- [x] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] 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: #5358
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5358
Pull-request-sha: 8a6e64323abeb9d08de3f68c63c6401ba1a5f847

Change-Id: I667657ee2d1d67b142f025257da7953a51c2ab7f

5 years agoMerge remote-tracking branch 'origin/pr/5358'
Mike Bayer [Thu, 28 May 2020 16:37:41 +0000 (12:37 -0400)] 
Merge remote-tracking branch 'origin/pr/5358'

Change-Id: Ibe7c41a7f3443eeef1eb3e8666f631bac05509fc

5 years agoFix 'email_address' being typoed as 'email_addres' in two places 5358/head
Mark Amery [Thu, 28 May 2020 12:37:24 +0000 (13:37 +0100)] 
Fix 'email_address' being typoed as 'email_addres' in two places

5 years agoRender table hints in generic SQL
Mike Bayer [Wed, 27 May 2020 14:18:33 +0000 (10:18 -0400)] 
Render table hints in generic SQL

Added :meth:`.Select.with_hint` output to the generic SQL string that is
produced when calling ``str()`` on a statement.  Previously, this clause
would be omitted under the assumption that it was dialect specific.
The hint text is presented within brackets to indicate the rendering
of such hints varies among backends.

Fixes: #5353
References: #4667
Change-Id: I01d97d6baa993e495519036ec7ecd5ae62856c16

5 years agoRevert 903b18828461bb8cb8dca4acc56809b3df2b14d5
Mike Bayer [Tue, 26 May 2020 03:26:18 +0000 (23:26 -0400)] 
Revert 903b18828461bb8cb8dca4acc56809b3df2b14d5

This was accidentally pushed just now.

Change-Id: I4da4151c4a81e5cf72146f8dcab3537301ccaae9

5 years agoUpdates for examples / performance
Mike Bayer [Tue, 26 May 2020 03:22:48 +0000 (23:22 -0400)] 
Updates for examples / performance

Change-Id: I55fc60258075f6f3efb7f738b900f60b2d2994c4

5 years agoSmall callcount reductions and refinement for cached queries
Mike Bayer [Tue, 26 May 2020 02:36:44 +0000 (22:36 -0400)] 
Small callcount reductions and refinement for cached queries

baked wasn't using the new one()/first()/one_or_none() methods,
fixed that.

loading._instance_processor() can skip setting up the
quick populators every time because it can cache the getters.

Callcounts have gone below what 1.3 does for the
test_baked_query performance suite, however runtime for
continued inexplicable reasons has not :(.   still suspecting
the result tuples but this seems so hard to believe.

Change-Id: Ifbca04834d27350e0fa82cb8512e66112abc8729

5 years agoAdd documentation regarding row constructo in PostgreSQL
Federico Caselli [Mon, 25 May 2020 19:43:58 +0000 (21:43 +0200)] 
Add documentation regarding row constructo in PostgreSQL

Fixes: #5331
Change-Id: Ia795a4d4d8ae4944d8a160d18f8b917177acf0de

5 years agoConvert execution to move through Session
Mike Bayer [Mon, 27 Apr 2020 16:58:12 +0000 (12:58 -0400)] 
Convert execution to move through Session

This patch replaces the ORM execution flow with a
single pathway through Session.execute() for all queries,
including Core and ORM.

Currently included is full support for ORM Query,
Query.from_statement(), select(), as well as the
baked query and horizontal shard systems.  Initial
changes have also been made to the dogpile caching
example, which like baked query makes use of a
new ORM-specific execution hook that replaces the
use of both QueryEvents.before_compile() as well
as Query._execute_and_instances() as the central
ORM interception hooks.

select() and Query() constructs alike can be passed to
Session.execute() where they will return ORM
results in a Results object.   This API is currently
used internally by Query.   Full support for
Session.execute()->results to behave in a fully
2.0 fashion will be in later changesets.

bulk update/delete with ORM support will also
be delivered via the update() and delete()
constructs, however these have not yet been adapted
to the new system and may follow in a subsequent
update.

Performance is also beginning to lag as of this
commit and some previous ones.   It is hoped that
a few central functions such as the coercions
functions can be rewritten in C to re-gain
performance.  Additionally, query caching
is now available and some subsequent patches
will attempt to cache more of the per-execution
work from the ORM layer, e.g. column getters
and adapters.

This patch also contains initial "turn on" of the
caching system enginewide via the query_cache_size
parameter to create_engine(). Still defaulting at
zero for "no caching".   The caching system still
needs adjustments in order to gain adequate performance.

Change-Id: I047a7ebb26aa85dc01f6789fac2bff561dcd555d

5 years agoUnify Query and select() , move all processing to compile phase
Mike Bayer [Sun, 1 Dec 2019 22:24:27 +0000 (17:24 -0500)] 
Unify Query and select() , move all processing to compile phase

Convert Query to do virtually all compile state computation
in the _compile_context() phase, and organize it all
such that a plain select() construct may also be used as the
source of information in order to generate ORM query state.
This makes it such that Query is not needed except for
its additional methods like from_self() which are all to
be deprecated.

The construction of ORM state will occur beyond the
caching boundary when the new execution model is integrated.

future select() gains a working join() and filter_by() method.
as we continue to rebase and merge each commit in the steps,
callcounts continue to bump around.  will have to look at
the final result when it's all in.

References: #5159
References: #4705
References: #4639
References: #4871
References: #5010

Change-Id: I19e05b3424b07114cce6c439b05198ac47f7ac10

5 years agoMerge "inline one_or_none"
mike bayer [Sun, 24 May 2020 15:51:24 +0000 (15:51 +0000)] 
Merge "inline one_or_none"

5 years agoAdd a docs link to the CockroachDB dialect
Rafi Shamim [Tue, 19 May 2020 17:42:49 +0000 (13:42 -0400)] 
Add a docs link to the CockroachDB dialect

This also increases the width of the table so that it's less likely the
whole table will need to be modified again in the future.

5 years agoinline one_or_none
Mike Bayer [Sun, 24 May 2020 13:41:51 +0000 (09:41 -0400)] 
inline one_or_none

Remove a bunch of unnecessary functions for this case.
add test coverage to ensure uniqueness logic works.

Change-Id: I2e6232c5667a3277b0ec8d7e47085a267f23d75f

5 years agoSYBASE: Added offset support
snowman2 [Sat, 9 May 2020 13:17:21 +0000 (09:17 -0400)] 
SYBASE: Added offset support

Fixes: #5294
### Description
Fix for https://github.com/sqlalchemy/sqlalchemy/issues/5294#issue-610311455

I tested it against our database (Adaptive Server Enterprise/16.0 SP02) with `pyodbc+sybase`

### Checklist

This pull request is:

- [x] A short code fix for #5294
- [x] Added tests.

Closes: #5312
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5312
Pull-request-sha: f62c14825f2941fdd54ede17fd8d4f105a052e05

Change-Id: Ic716e17a6f654deef78781cefc3f16333cd725c3

5 years agoAvoid proxy functions in row functions
Federico Caselli [Thu, 21 May 2020 19:50:49 +0000 (21:50 +0200)] 
Avoid proxy functions in row functions

This streamlines a bit for non-C implementations, however
also adds and tests behavioral contracts that mappings should
not allow integer or slice access and should behave like a
Python mapping in that it raises KeyError for an integer
and TypeError for a slice.   Py3/Py2/C/noC :)

References: #5340
Change-Id: Id3cef452dc8a526b8371c90c5ca2bbb240b25c26

5 years agoMerge "Add python 3.8 profiles; remove zoomark tests"
mike bayer [Sat, 23 May 2020 23:28:52 +0000 (23:28 +0000)] 
Merge "Add python 3.8 profiles; remove zoomark tests"

5 years agoMerge "Correctly apply self_group in type_coerce element."
mike bayer [Sat, 23 May 2020 21:21:39 +0000 (21:21 +0000)] 
Merge "Correctly apply self_group in type_coerce element."

5 years agoMerge "Add with_for_update mysql new functionalities"
mike bayer [Sat, 23 May 2020 21:14:27 +0000 (21:14 +0000)] 
Merge "Add with_for_update mysql new functionalities"

5 years agoMerge "Improve error message when using :meth:`_query.Query.filter_by` in a query...
mike bayer [Sat, 23 May 2020 21:11:50 +0000 (21:11 +0000)] 
Merge "Improve error message when using :meth:`_query.Query.filter_by` in a query where the first entity is not a mapped class."

5 years agoMerge "Add note re: pymssql not in CI"
mike bayer [Sat, 23 May 2020 21:10:59 +0000 (21:10 +0000)] 
Merge "Add note re: pymssql not in CI"

5 years agoMerge "fix typo in reference documentation"
mike bayer [Sat, 23 May 2020 21:10:14 +0000 (21:10 +0000)] 
Merge "fix typo in reference documentation"

5 years agoAdd python 3.8 profiles; remove zoomark tests
Federico Caselli [Fri, 22 May 2020 20:48:16 +0000 (22:48 +0200)] 
Add python 3.8 profiles; remove zoomark tests

The zoomark tests have served us well for many years.
At this point, they have been using a very antiquated
calling style for many years and are no longer where we catch
performance issues.
The performance suite now has a large number of individual
tests that catch issues very specifically and additionally
record just one performance count per test.   This also
allows us to remove the "replay" fixtures that were not
used for anything else.

Fixes: #5347
Change-Id: I0a8d078e7b7240602f4f3f7068f231e98a40f17e

5 years agoStop converting mssql datetime.time parameters to datetime.datetime
Gord Thompson [Thu, 21 May 2020 22:20:48 +0000 (16:20 -0600)] 
Stop converting mssql datetime.time parameters to datetime.datetime

Fixes: #5339
Change-Id: Ida75422d8c3fdfc7adae68e547d88df49368a693

5 years agoMerge "Add immutabledict C code"
mike bayer [Sat, 23 May 2020 12:51:07 +0000 (12:51 +0000)] 
Merge "Add immutabledict C code"

5 years agoAdd immutabledict C code
Mike Bayer [Fri, 22 May 2020 04:06:06 +0000 (00:06 -0400)] 
Add immutabledict C code

Start trying to convert fundamental objects to
C as we now rely on a fairly small core of things,
and 1.4 is having problems with complexity added being
slower than the performance gains we are trying to build in.

immutabledict here does seem to bench as twice as fast as the
Python one, see below.  However, it does not appear to be
used prominently enough to make any dent in the performance
tests.

at the very least it may provide us some more lift-and-copy
code for more C extensions.

import timeit

from sqlalchemy.util._collections import not_immutabledict, immutabledict

def run(dict_cls):
    for i in range(1000000):
        d1 = dict_cls({"x": 5, "y": 4})

        d2 = d1.union({"x": 17, "new key": "some other value"}, None)

        assert list(d2) == ["x", "y", "new key"]

print(
    timeit.timeit(
        "run(d)", "from __main__ import run, not_immutabledict as d", number=1
    )
)
print(
    timeit.timeit(
        "run(d)", "from __main__ import run, immutabledict as d", number=1
    )
)

output:

python: 1.8799766399897635
C code: 0.8880784640205093

Change-Id: I29e7104dc21dcc7cdf895bf274003af2e219bf6d

5 years agofix typo in reference documentation
Federico Caselli [Fri, 22 May 2020 22:11:46 +0000 (00:11 +0200)] 
fix typo in reference documentation

Change-Id: I5720635863f0d8a8ebfa4ddc51008bb93c1067b4

5 years agoCorrectly apply self_group in type_coerce element.
Federico Caselli [Fri, 22 May 2020 21:56:50 +0000 (23:56 +0200)] 
Correctly apply self_group in type_coerce element.

The type coerce element did not correctly apply grouping rules when using
in an expression

Fixes: #5344
Change-Id: Id67b0e60ac54f8992f931aaed62731672f60c96c

5 years agoMerge "Fix query string escaping in engine URLs"
mike bayer [Fri, 22 May 2020 20:17:49 +0000 (20:17 +0000)] 
Merge "Fix query string escaping in engine URLs"

5 years agoMerge "Don't emit pyodbc "no driver" warning for empty URL"
mike bayer [Fri, 22 May 2020 20:12:42 +0000 (20:12 +0000)] 
Merge "Don't emit pyodbc "no driver" warning for empty URL"

5 years agoCross reference do_connect() event w/ creator
Mike Bayer [Fri, 22 May 2020 20:04:17 +0000 (16:04 -0400)] 
Cross reference do_connect() event w/ creator

two questions today involving creator / do_connect,
do_connect is not well known enough, ensure docs are present
and prominent.

Change-Id: I85d518b9fc7b9b069a18010969abefa360134fe9

5 years agoDon't emit pyodbc "no driver" warning for empty URL
Mike Bayer [Fri, 22 May 2020 17:14:58 +0000 (13:14 -0400)] 
Don't emit pyodbc "no driver" warning for empty URL

Fixed an issue in the pyodbc connector such that a warning about pyodbc
"drivername" would be emitted when using a totally empty URL.  Empty URLs
are normal when producing a non-connected dialect object or when using the
"creator" argument to create_engine(). The warning now only emits if the
driver name is missing but other parameters are still present.

Fixes: #5346
Change-Id: I0ee6f5fd5af7faca63bf0d7034410942f40834a8

5 years agoMerge "Structural / performance refinements"
mike bayer [Fri, 22 May 2020 15:45:57 +0000 (15:45 +0000)] 
Merge "Structural / performance refinements"

5 years agoStructural / performance refinements
Mike Bayer [Thu, 21 May 2020 22:18:39 +0000 (18:18 -0400)] 
Structural / performance refinements

* state connection schema_translate_map entirely in terms of
  execution options, support for per-execution options as well

* use slots for role impls, remove superclass of the roles
  themselves as this is not needed

* tighten loop in resolve, might become a C function

Change-Id: Ib98ac9b65022fbf976e49c6060e4c37573528c5f

5 years agoDon't incref on new reference key_style
Mike Bayer [Fri, 22 May 2020 14:13:02 +0000 (10:13 -0400)] 
Don't incref on new reference key_style

in 4550983e0ce2f35b3585e53894c941c23693e71d we
added a new attribute key_style.  remove an erroneous
Py_INCREF when we acquire it from PyLong_FromLong
as we already own the reference.    since this
is a new reference we actualy need to Py_DECREF
it because we aren't returning it.

Change-Id: I61470513a173c76863ec6f7f5ff9b2ec13582f08

5 years agoMerge "Performance fixes for new result set"
mike bayer [Thu, 21 May 2020 19:03:32 +0000 (19:03 +0000)] 
Merge "Performance fixes for new result set"

5 years agoFix query string escaping in engine URLs
Miguel Grinberg [Thu, 21 May 2020 09:54:47 +0000 (05:54 -0400)] 
Fix query string escaping in engine URLs

Fixed issue in :class:`.URL` object where stringifying the object
would not URL encode special characters, preventing the URL from being
re-consumable as a real URL.  Pull request courtesy Miguel Grinberg.

Fixes: #5341
Closes: #5342
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5342
Pull-request-sha: 362ca3398336a3a892e8020530f0c68d4f2d1d01

Change-Id: Ief6218122d1ec0c70479eb1a90e1c16433801924

5 years agoPerformance fixes for new result set
Mike Bayer [Wed, 20 May 2020 17:41:44 +0000 (13:41 -0400)] 
Performance fixes for new result set

A few small mistakes led to huge callcounts.   Additionally,
the warn-on-get behavior which is attempting to warn for
deprecated access in SQLAlchemy 2.0 is very expensive; it's not clear
if its feasible to have this warning or to somehow alter how it
works.

Fixes: #5340
Change-Id: I73bdd2d7b6f1b25cc0222accabd585cf761a5af4

5 years agoTarget real pypi in the create wheel workflow
Federico Caselli [Wed, 20 May 2020 19:31:16 +0000 (21:31 +0200)] 
Target real pypi in the create wheel workflow

Change-Id: Ic764aae08b9d45011048f21c8ee992222c078bd2

5 years agofix table.schema version to 1.3.18
Mike Bayer [Tue, 19 May 2020 22:55:16 +0000 (18:55 -0400)] 
fix table.schema version to 1.3.18

Fixes: #5338
Change-Id: I12ce8021f5627c306c768b74da991ef4af0a5b55

5 years agoMerge "SQLite 3.31 added support for computed column."
mike bayer [Tue, 19 May 2020 20:18:40 +0000 (20:18 +0000)] 
Merge "SQLite 3.31 added support for computed column."

5 years agoMerge "Introduce :class:`.IdentityOptions` to store common parameters for sequences...
mike bayer [Tue, 19 May 2020 19:47:16 +0000 (19:47 +0000)] 
Merge "Introduce :class:`.IdentityOptions` to store common parameters for sequences and identity columns."

5 years agoDisable "check unicode returns" under Python 3
Mike Bayer [Thu, 7 May 2020 14:53:15 +0000 (10:53 -0400)] 
Disable "check unicode returns" under Python 3

Disabled the "unicode returns" check that runs on dialect startup when
running under Python 3, which for many years has occurred in order to test
the current DBAPI's behavior for whether or not it returns Python Unicode
or Py2K strings for the VARCHAR and NVARCHAR datatypes.  The check still
occurs by default under Python 2, however the mechanism to test the
behavior will be removed in SQLAlchemy 2.0 when Python 2 support is also
removed.

This logic was very effective when it was needed, however now that Python 3
is standard, all DBAPIs are expected to return Python 3 strings for
character datatypes.  In the unlikely case that a third party DBAPI does
not support this, the conversion logic within :class:`.String` is still
available and the third party dialect may specify this in its upfront
dialect flags by setting the dialect level flag ``returns_unicode_strings``
to one of :attr:`.String.RETURNS_CONDITIONAL` or
:attr:`.String.RETURNS_BYTES`, both of which will enable Unicode conversion
even under Python 3.

As part of this change, disabling testing of the doctest tutorials under
Python 2.

Fixes: #5315
Change-Id: I1260e894611409d3b7fe1a92bd90c52043bbcf19

5 years agoSQLite 3.31 added support for computed column.
Federico Caselli [Fri, 1 May 2020 20:22:51 +0000 (22:22 +0200)] 
SQLite 3.31 added support for computed column.

This change enables their support in SQLAlchemy when targeting SQLite.

Fixes: #5297
Change-Id: Ia9f21a49e58fc977e3c669b8176036c95d93b9c8

5 years agoStreamline visitors.iterate
Mike Bayer [Mon, 18 May 2020 20:08:33 +0000 (16:08 -0400)] 
Streamline visitors.iterate

This method might be used more significantly in the
ORM refactor, so further refine it.

* all get_children() methods now work entirely based on iterators.
  Basically only select() was sensitive to this anymore and it now
  chains the iterators together

* remove all kinds of flags like column_collections, schema_visitor
  that apparently aren't used anymore.

* remove the "depthfirst" visitors as these don't seem to be
  used either.

* make sure select() yields its columns first as these will be used
  to determine the current mapper.

Change-Id: I05273a2d5306a57c2d1b0979050748cf3ac964bf

5 years agoMerge "Update transaction / connection handling"
mike bayer [Sun, 17 May 2020 22:00:16 +0000 (22:00 +0000)] 
Merge "Update transaction / connection handling"

5 years agoUpdate transaction / connection handling
Mike Bayer [Thu, 14 May 2020 16:50:11 +0000 (12:50 -0400)] 
Update transaction / connection handling

step one, do away with __connection attribute and using
awkward AttributeError logic

step two, move all management of "connection._transaction"
into the transaction objects themselves where it's easier
to follow.

build MarkerTransaction that takes the role of
"do-nothing block"

new connection datamodel is: connection._transaction, always
a root, connection._nested_transaction, always a nested.

nested transactions still chain to each other as this
is still sort of necessary but they consider the root
transaction separately, and the marker transactions
not at all.

introduce new InvalidRequestError subclass
PendingRollbackError.  Apply to connection and session
for all cases where a transaction needs to be rolled
back before continuing.   Within Connection,
both PendingRollbackError as well as ResourceClosedError
are now raised directly without being handled by
handle_dbapi_error();  this removes these two exception
cases from the handle_error event handler as well as
from StatementError wrapping, as these two exceptions are
not statement oriented and are instead programmatic
issues, that the application is failing to handle database
errors properly.

Revise savepoints so that when a release fails, they set
themselves as inactive so that their rollback() method
does not throw another exception.

Give savepoints another go on MySQL, can't get release working
however get support for basic round trip going

Fixes: #5327
Change-Id: Ia3cbbf56d4882fcc7980f90519412f1711fae74d

5 years agoReword delete-orphan on many error message and document
Mike Bayer [Sat, 16 May 2020 17:05:00 +0000 (13:05 -0400)] 
Reword delete-orphan on many error message and document

For many years we have encountered users making use of the
"single_parent" flag in response to the error message for
"delete-orphan" expressing this as a means to cancel the current
error.   However, the actual issue here is usually a misuse
of the delete-orphan cascade setting.  Reword the error message to
be much more descriptive about what this means and add new
error link sections describing the situation in as much detail
as possible.

Fixes: #5329
Change-Id: I7ba710378b2935479ab22ff9a0a79c692dbf69a6

5 years agoAdd note re: pymssql not in CI
Gord Thompson [Sat, 16 May 2020 14:57:06 +0000 (08:57 -0600)] 
Add note re: pymssql not in CI

Change-Id: I45f78131ffe1881a3965e8aa41bbc46da7d43a5b

5 years agoIntroduce :class:`.IdentityOptions` to store common parameters for
Federico Caselli [Thu, 14 May 2020 20:57:56 +0000 (22:57 +0200)] 
Introduce :class:`.IdentityOptions` to store common parameters for
sequences and identity columns.

References: #5324
Change-Id: I72f7fc1a003456206b004d3d26306940f9c36414

5 years agoAdd with_for_update mysql new functionalities
RobotScribe [Wed, 29 Apr 2020 19:22:59 +0000 (15:22 -0400)] 
Add with_for_update mysql new functionalities

Fixes: #4860
# Description
Add nowait, skip_lock, of arguments to for_update_clause for mysql

### Checklist

This pull request is:

- [ ] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] 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.
- [x] 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: #5290
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5290
Pull-request-sha: 490e822e73e92ffe63cf45df9c49f3b31af1954d

Change-Id: Ibd2acc47b538c601c69c8fb954776035ecab4c6c

5 years agoMerge "Add 'schema' parameter to table"
mike bayer [Fri, 15 May 2020 17:11:20 +0000 (17:11 +0000)] 
Merge "Add 'schema' parameter to table"