Mike Bayer [Fri, 5 Jul 2024 13:30:10 +0000 (09:30 -0400)]
alter the collation of string type for collate()
Fixed issue where the :func:`_sql.collate` construct, which explicitly sets
a collation for a given expression, would maintain collation settings for
the underlying type object from the expression, causing SQL expressions to
have both collations stated at once when used in further expressions for
specific dialects that render explicit type casts, such as that of asyncpg.
The :func:`_sql.collate` construct now assigns its own type to explicitly
include the new collation, assuming it's a string type.
Mike Bayer [Wed, 3 Jul 2024 19:46:30 +0000 (15:46 -0400)]
add special rule to honor UPPERCASE name for TExtualSelect
Fixed issue in name normalization (e.g. "uppercase" backends like Oracle)
where using a :class:`.TextualSelect` would not properly maintain as
uppercase column names that were quoted as uppercase, even though
the :class:`.TextualSelect` includes a :class:`.Column` that explicitly
holds this uppercase name.
* Added valid types to server_onupdate and mapped_column kwargs mypy tests
* Joined mapped_column test files
* Set _ServerOnUpdateArgument to _ServerDefaultArgument
Eric Atkin [Wed, 3 Jul 2024 20:05:04 +0000 (16:05 -0400)]
Allow flat for join with name
The :paramref:`_orm.aliased.name` parameter to :func:`_orm.aliased` may now
be combined with the :paramref:`_orm.aliased.flat` parameter, producing
per-table names based on a name-prefixed naming convention. Pull request
courtesy Eric Atkin.
Mike Bayer [Thu, 21 Dec 2023 17:14:00 +0000 (12:14 -0500)]
use driver col names
Added new execution option
:paramref:`_engine.Connection.execution_options.driver_column_names`. This
option disables the "name normalize" step that takes place against the
DBAPI ``cursor.description`` for uppercase-default backends like Oracle,
and will cause the keys of a result set (e.g. named tuple names, dictionary
keys in :attr:`.Row._mapping`, etc.) to be exactly what was delivered in
cursor.description. This is mostly useful for plain textual statements
using :func:`_sql.text` or :meth:`_engine.Connection.exec_driver_sql`.
Mike Bayer [Tue, 2 Jul 2024 17:57:47 +0000 (13:57 -0400)]
call iter() on detached/transient dynamic session
Fixed regression going back to 1.4 where accessing a collection using the
"dynamic" strategy on a transient object and attempting to query would
raise an internal error rather than the expected :class:`.NoResultFound`
that occurred in 1.3.
Mike Bayer [Fri, 28 Jun 2024 20:30:57 +0000 (16:30 -0400)]
handle DBAPI error for fetchall()
Fixed issue in "insertmanyvalues" feature where a particular call to
``cursor.fetchall()`` were not wrapped in SQLAlchemy's exception wrapper,
which apparently can raise a database exception during fetch when using
pyodbc.
lonkeknol [Fri, 28 Jun 2024 16:27:33 +0000 (12:27 -0400)]
Docs: simplify language in getting a connection & committing changes
### Description
Simplifies language use in [Getting a Connection](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#getting-a-connection) and [Committing Changes](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#committing-changes)
### Checklist
This pull request is:
- [x] A documentation / typographical / small typing 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.
Mike Bayer [Thu, 27 Jun 2024 22:17:47 +0000 (18:17 -0400)]
cache key share; support correct traverse of 'of'
Fixed caching issue where the
:paramref:`_sql.Select.with_for_update.key_share` element of
:meth:`_sql.Select.with_for_update` was not considered as part of the cache
key, leading to incorrect caching if different variations of this parameter
were used with an otherwise identical statement.
Also repairs a traversal issue where the ``of`` element of
``ForUpdateArg`` when set to ``None`` cannot be compared against a
non-None element because the traversal defines it as a clauselist.
Traversal in this case is adjusted to accommodate for this case so that
we dont need to create a risky-to-backport change to ``ForUpdateArg``
itself.
lonkeknol [Thu, 27 Jun 2024 13:03:30 +0000 (09:03 -0400)]
Docs: simplify language use for "Working with Transactions and the DBAPI"
### Description
This is my first pull request to sqlalchemy. It changes the writing style of two paragraphs in the unified tutorial [here](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#working-with-transactions-and-the-dbapi). My goals were to.
1. Make them easier to read
2. Not change the meaning of the text.
3. Get feedback on whether this type of contribution is considered useful for sqlalchemy.
If this is a useful type of contribution, it might be good to discuss some general guidelines for me to adhere to as I continue. For instance:
- Prefer using present simple tense
- Remove superfluous words where possible
- Keep the pull requests to one or two h2 sections at a time, to make the review easier
### Checklist
This pull request is:
- [x] A documentation / typographical / small typing 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.
I'm curious to hear what you all think. **Have a nice day!**
Mike Bayer [Wed, 26 Jun 2024 16:13:28 +0000 (12:13 -0400)]
add additional test cases re: #11371
Just want to make sure aliased() and with_polymorphic() still
work in the of_type() context here, since that's likely why we
had Any for this parameter in the first place
Federico Caselli [Fri, 15 Mar 2024 18:15:27 +0000 (19:15 +0100)]
Ignore join_transaction_mode when bind is an engine
Ignore :paramref:`_orm.Session.join_transaction_mode` in all cases when
the bind provided to the :class:`_orm.Session` is an
class:`_engine.Engine`.
Previously if an event that executed before the session logic,
like :meth:`_engine.ConnectionEvents.engine_connect`,
left the connection with an active transaction, the
paramref:`_orm.Session.join_transaction_mode` behavior took
place, leading to a surprising behavior.
Mike Bayer [Sun, 23 Jun 2024 19:40:31 +0000 (15:40 -0400)]
use a new ClauseElement for Over.range_ / Over.rows
Enhanced the caching structure of the :paramref:`.over.rows` and
:paramref:`.over.range` so that different numerical values for the rows /
range fields are cached on the same cache key, to the extent that the
underlying SQL does not actually change (i.e. "unbounded", "current row",
negative/positive status will still change the cache key). This prevents
the use of many different numerical range/rows value for a query that is
otherwise identical from filling up the SQL cache.
Note that the semi-private compiler method ``_format_frame_clause()``
is removed by this fix, replaced with a new method
``visit_frame_clause()``. Third party dialects which may have referred
to this method will need to change the name and revise the approach to
rendering the correct SQL for that dialect.
This patch introduces a new ClauseElement called _FrameClause which
stores the integer range values separately and within cache-compatible
BindParameter objects from the "type" which
can be unbounded, current, preceding, or following, represented by
a _FrameClauseType enum. The negative
sign is also stripped from the integer and represented within the
_FrameClauseType. Tests from #11514 are adapted to include
a test for SQL Server's "literal_execute" flag taking effect so
that literal numeric values aren't stored in the cache.
Mike Bayer [Mon, 24 Jun 2024 19:07:41 +0000 (15:07 -0400)]
create JoinedDispatcher subclasses up front
Fixed additional issues in the event system triggered by unpickling of a
:class:`.Enum` datatype, continuing from :ticket:`11365` and
:ticket:`11360`, where dynamically generated elements of the event
structure would not be present when unpickling in a new process.
Mike Bayer [Wed, 19 Jun 2024 15:03:25 +0000 (11:03 -0400)]
use literal execute for SQL Server frame parameters
Fixed issue where SQL Server drivers don't support bound parameters when
rendering the "frame specification" for a window function, e.g. "ROWS
BETWEEN", etc.
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
Correct documentation according to discussion: https://github.com/sqlalchemy/sqlalchemy/discussions/11481#discussioncomment-9759171
### 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 / small typing 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.
Mike Bayer [Tue, 18 Jun 2024 02:45:16 +0000 (22:45 -0400)]
restore declared_attr consumption for __table__
Fixed bug in ORM Declarative where the ``__table__`` directive could not be
declared as a class function with :func:`_orm.declared_attr` on a
superclass, including an ``__abstract__`` class as well as coming from the
declarative base itself. This was a regression since 1.4 where this was
working, and there were apparently no tests for this particular use case.
Mike Bayer [Wed, 12 Jun 2024 16:42:29 +0000 (12:42 -0400)]
open up async greenlet for third parties
Modified the internal representation used for adapting asyncio calls to
greenlets to allow for duck-typed compatibility with third party libraries
that implement SQLAlchemy's "greenlet-to-asyncio" pattern directly.
Running code within a greenlet that features the attribute
``__sqlalchemy_greenlet_provider__ = True`` will allow calls to
:func:`sqlalchemy.util.await_only` directly.
Mike Bayer [Tue, 11 Jun 2024 13:16:26 +0000 (09:16 -0400)]
loosen up hash_limit test
hash_limit_string works by doing a modulus of a hash value so that
the range of possible numbers is 0-N. however, there's a chance
we might not populate every 0-N value in unusual cases on CI,
even after iterating 500 times apparently. Loosen the change by making
sure we got at least N/2 unique hash messages but not greater
than N.
Mike Bayer [Tue, 11 Jun 2024 02:59:49 +0000 (22:59 -0400)]
include HasCTE traversal elements in TextualSelect
Fixed caching issue where using the :meth:`.TextualSelect.add_cte` method
of the :class:`.TextualSelect` construct would not set a correct cache key
which distinguished between different CTE expressions.
Mike Bayer [Tue, 4 Jun 2024 14:56:26 +0000 (10:56 -0400)]
add additional contextual path info when splicing eager joins
Fixed very old issue involving the :paramref:`_orm.joinedload.innerjoin`
parameter where making use of this parameter mixed into a query that also
included joined eager loads along a self-referential or other cyclical
relationship, along with complicating factors like inner joins added for
secondary tables and such, would have the chance of splicing a particular
inner join to the wrong part of the query. Additional state has been added
to the internal method that does this splice to make a better decision as
to where splicing should proceed.
Mike Bayer [Mon, 3 Jun 2024 18:50:25 +0000 (14:50 -0400)]
expand entity_isa to include simple "isa" in poly case
Fixed issue where the :func:`_orm.selectinload` and
:func:`_orm.subqueryload` loader options would fail to take effect when
made against an inherited subclass that itself included a subclass-specific
:paramref:`_orm.Mapper.with_polymorphic` setting.
Federico Caselli [Wed, 29 May 2024 19:39:08 +0000 (21:39 +0200)]
Make `FunctionFilter.filter` generative
Fixed bug in :meth:`_sql.FunctionFilter.filter` that would mutate
the existing function in-place. It now behaves like the rest of the
SQLAlchemy API, returning a new instance instead of mutating the
original one.
Mike Bayer [Sun, 26 May 2024 15:34:27 +0000 (11:34 -0400)]
skip dunders for langhelper symbol redefine; update tox
Set up full Python 3.13 support to the extent currently possible, repairing
issues within internal language helpers as well as the serializer extension
module.
update tox for what will be a regular condition: greenlet is
not available (and possibly other things like pymssql):
1. dont use "sqlalchemy[asyncio]" in pyproejct.toml as an extra; this
goes out to pypi and ignores the local file
2. add py{3,38,39,...} qualifiers for asyncio deps in tox.ini. After
many attempts I seem to have something that's fairly non-repetetive
though I'd still prefer a single variable for this, somehow
Mike Bayer [Fri, 24 May 2024 14:58:02 +0000 (10:58 -0400)]
Add test for issue 11412
Issue #10365 was found to also fix an issue where
single-inheritance criteria would not be correctly applied to a
subclass entity that only appeared in the ``select_from()`` list.
Semyon Pupkov [Sat, 11 May 2024 12:41:06 +0000 (08:41 -0400)]
Optimize has_intersection func
<!-- Provide a general summary of your proposed changes in the Title field above -->
Optimize `has_intersection` function. It uses in few places, but even so it might be optimized. New version:
1. Does not allocate new set
2. A bit of performance speedup
```
from sqlalchemy import util
import timeit
import functools
a = {1, 2, 3}
b = [2, 3, 4]
t1 = timeit.Timer(functools.partial(util.has_intersection, a, b))
t2 = timeit.Timer(functools.partial(util.has_intersection2, a, b))
### Description
<!-- Describe your changes in detail -->
### 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 / small typing 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.
Improvement is about 10%
(Table must be manually constructed by running
`python test/perf/compiled_extensions CacheKey` on main and in
this change while recompiling cython)
Mike Bayer [Tue, 7 May 2024 22:03:51 +0000 (18:03 -0400)]
setup JoinedDispatch to support pickling
Fixed issue where a :class:`.MetaData` collection would not be
serializable, if an :class:`.Enum` or :class:`.Boolean` datatype were
present which had been adapted. This specific scenario in turn could occur
when using the :class:`.Enum` or :class:`.Boolean` within ORM Annotated
Declarative form where type objects frequently get copied.
Mike Bayer [Sat, 4 May 2024 14:38:48 +0000 (10:38 -0400)]
revise approach for bundle deduping
Revise the approach from 7d6d7ef73 to make a special case for
Bundle-targeted columns entirely, and don't involve the
_label_convention() callable. Add tests for select() with
tablename labeling convention.
Mark Elliot [Mon, 29 Apr 2024 21:50:10 +0000 (17:50 -0400)]
Add overload for ColumnCollection.get(col, default)
### Description
Fixes #11328 by adding an overload to ColumnCollection when a non-None default is provided.
### Checklist
This pull request is:
- [ ] A documentation / typographical / small typing 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.
Carlos Sousa [Mon, 8 Jan 2024 19:50:02 +0000 (14:50 -0500)]
Warn in execute when parameter is an empty list
An empty sequence passed to any ``execute()`` method now
raised a deprecation warning, since such an executemany
is invalid.
Pull request courtesy of Carlos Sousa.
Mike Bayer [Thu, 2 May 2024 23:05:08 +0000 (19:05 -0400)]
correctly apply _set_binops_check_strict to AssociationProxy
Revised the set "binary" operators for the association proxy ``set()``
interface to correctly raise ``TypeError`` for invalid use of the ``|``,
``&``, ``^``, and ``-`` operators, as well as the in-place mutation
versions of these methods, to match the behavior of standard Python
``set()`` as well as SQLAlchemy ORM's "intstrumented" set implementation.
Fixed issue in ORM Annotated Declarative where typing issue where literals
defined using :pep:`695` type aliases would not work with inference of
:class:`.Enum` datatypes. Pull request courtesy of Alc-Alc.
Mike Bayer [Thu, 2 May 2024 15:45:31 +0000 (11:45 -0400)]
disable col deduping inside of Bundle
Fixed issue where attribute key names in :class:`_orm.Bundle` would not be
correct when using ORM enabled :class:`_sql.select` vs.
:class:`_orm.Query`, when the statement contained duplicate column names.
Fixed issue in typing for :class:`_orm.Bundle` where creating a nested
:class:`_orm.Bundle` structure were not allowed.