Mike Bayer [Thu, 12 Mar 2015 14:14:52 +0000 (10:14 -0400)]
- try to document how to get columns from constraints.
unfortunately Sphinx refuses to work correctly for the columns
attribute so we just add a lame message to contains_column().
Mike Bayer [Thu, 12 Mar 2015 00:22:42 +0000 (20:22 -0400)]
- Added a new extension suite :mod:`sqlalchemy.ext.baked`. This
simple but unusual system allows for a dramatic savings in Python
overhead for the construction and processing of orm :class:`.Query`
objects, from query construction up through rendering of a string
SQL statement.
fixes #3054
Mike Bayer [Wed, 11 Mar 2015 18:46:52 +0000 (14:46 -0400)]
- Added a new entry ``"entity"`` to the dictionaries returned by
:attr:`.Query.column_descriptions`. This refers to the primary ORM
mapped class or aliased class that is referred to by the expression.
Compared to the existing entry for ``"type"``, it will always be
a mapped entity, even if extracted from a column expression, or
None if the given expression is a pure core expression.
references #3320
Mike Bayer [Wed, 11 Mar 2015 15:41:52 +0000 (11:41 -0400)]
- The Postgresql :class:`.postgresql.ENUM` type will emit a
DROP TYPE instruction when a plain ``table.drop()`` is called,
assuming the object is not associated directly with a
:class:`.MetaData` object. In order to accomodate the use case of
an enumerated type shared between multiple tables, the type should
be associated directly with the :class:`.MetaData` object; in this
case the type will only be created at the metadata level, or if
created directly. The rules for create/drop of
Postgresql enumerated types have been highly reworked in general.
fixes #3319
Mike Bayer [Tue, 10 Mar 2015 23:56:59 +0000 (19:56 -0400)]
- Added a new event suite :class:`.QueryEvents`. The
:meth:`.QueryEvents.before_compile` event allows the creation
of functions which may place additional modifications to
:class:`.Query` objects before the construction of the SELECT
statement. It is hoped that this event be made much more
useful via the advent of a new inspection system that will
allow for detailed modifications to be made against
:class:`.Query` objects in an automated fashion.
fixes #3317
Mike Bayer [Tue, 10 Mar 2015 22:23:23 +0000 (18:23 -0400)]
- The subquery wrapping which occurs when joined eager loading
is used with a one-to-many query that also features LIMIT,
OFFSET, or DISTINCT has been disabled in the case of a one-to-one
relationship, that is a one-to-many with
:paramref:`.relationship.uselist` set to False. This will produce
more efficient queries in these cases.
fixes #3249
Mike Bayer [Tue, 10 Mar 2015 21:51:35 +0000 (17:51 -0400)]
- Fixed bug where the session attachment error "object is already
attached to session X" would fail to prevent the object from
also being attached to the new session, in the case that execution
continued after the error raise occurred.
fixes #3301
Mike Bayer [Tue, 10 Mar 2015 21:21:46 +0000 (17:21 -0400)]
- Fixed bug where using an ``__abstract__`` mixin in the middle
of a declarative inheritance hierarchy would prevent attributes
and configuration being correctly propagated from the base class
to the inheriting class.
fixes #3219 fixes #3240
Mike Bayer [Mon, 9 Mar 2015 19:24:37 +0000 (15:24 -0400)]
- fix a potential race condition where the per-mapper LRUCache used by
persistence.py could theoretically hit the limit of the cache
(100 items by default) and at some points fail to have a key that
we check for, due to the cleanup. This has never been observed
so its likely that so far, the total number of INSERT, UPDATE and
DELETE statement structures in real apps has not exceeded 100
on a per-mapper basis; this could happen for apps that run a
very wide variety of attribute modified combinations into the unit
of work, *and* which have very high concurrency going on.
This change will be a lot more significant when we open up
use of LRUCache + compiled cache with the baked query extension.
Mike Bayer [Mon, 9 Mar 2015 19:24:01 +0000 (15:24 -0400)]
- reduce some callcounts related to the lightweight tuple,
basically by caching them.
- improve LRUCache so that size management only proceeds
in one thread, add a real get() method
Mike Bayer [Mon, 9 Mar 2015 16:26:30 +0000 (12:26 -0400)]
- we really don't want to force lib here, but we do need
it for the plain "pytest" case, so do an append instead of an insert
- add a new tox file to do a full regen of callcounts
Mike Bayer [Sun, 8 Mar 2015 03:51:12 +0000 (22:51 -0500)]
- the change for #918 was of course not nearly that simple.
The "wrapping" employed by the mssql and oracle dialects using the
"iswrapper" argument was not being used intelligently by the compiler,
and the result map was being written incorrectly, using
*more* columns in the result map than were actually returned by
the statement, due to "row number" columns that are inside the
subquery. The compiler now writes out result map on the
"top level" select in all cases
fully, and for the mssql/oracle wrapping case extracts out
the "proxied" columns in a second step, which only includes
those columns that are proxied outwards to the top level.
This change might have implications for 3rd party dialects that
might be imitating oracle's approach. They can safely continue
to use the "iswrapper" kw which is now ignored, but they may
need to also add the _select_wraps argument as well.
Mike Bayer [Sat, 7 Mar 2015 17:48:13 +0000 (12:48 -0500)]
- The SQL compiler now generates the mapping of expected columns
such that they are matched to the received result set positionally,
rather than by name. Originally, this was seen as a way to handle
cases where we had columns returned with difficult-to-predict names,
though in modern use that issue has been overcome by anonymous
labeling. In this version, the approach basically reduces function
call count per-result by a few dozen calls, or more for larger
sets of result columns. The approach still degrades into a modern
version of the old approach if textual elements modify the result
map, or if any discrepancy in size exists between
the compiled set of columns versus what was received, so there's no
issue for partially or fully textual compilation scenarios where these
lists might not line up. fixes #918
- callcounts still need to be adjusted down for this so zoomark
tests won't pass at the moment
Mike Bayer [Sun, 1 Mar 2015 21:09:11 +0000 (16:09 -0500)]
- squash-merge the final row_proc integration branch. this is
a much more modest outcome than what we started with. The
work of create_row_processor() for ColumnProperty objects
is essentially done at query setup time combined with some
lookups in _instance_processor().
- to allow this change for deferred columns, deferred columns
no longer search for themselves in the result. If they've been
set up as deferred without any explicit directive to undefer them,
then this is what was asked for. if we don't do this,
then we're stuck with this performance penalty for all deferred
columns which in the vast majority of typical use cases (e.g. loading
large, legacy tables or tables with many/large very seldom
used values) won't be present in the result and won't be accessed at all.
Mike Bayer [Tue, 24 Feb 2015 20:29:30 +0000 (15:29 -0500)]
- repair issue in declared_attr.cascading such that within a
subclass, the value returned by the descriptor is not available
because the superclass is already mapped with the InstrumentedAttribute,
until the subclass is mapped. We add a setattr() to set up that
attribute so that the __mapper_args__ hook and possibly others
have access to the "cascaded" version of the attribute within
the call.
Mike Bayer [Fri, 20 Feb 2015 20:14:08 +0000 (15:14 -0500)]
- Fixed bugs in ORM object comparisons where comparison of
many-to-one ``!= None`` would fail if the source were an aliased
class, or if the query needed to apply special aliasing to the
expression due to aliased joins or polymorphic querying; also fixed
bug in the case where comparing a many-to-one to an object state
would fail if the query needed to apply special aliasing
due to aliased joins or polymorphic querying.
fixes #3310
Mike Bayer [Fri, 20 Feb 2015 05:01:19 +0000 (00:01 -0500)]
- Fixed bug where internal assertion would fail in the case where
an ``after_rollback()`` handler for a :class:`.Session` incorrectly
adds state to that :class:`.Session` within the handler, and the task
to warn and remove this state (established by :ticket:`2389`) attempts
to proceed.
fixes #3309
Mike Bayer [Wed, 18 Feb 2015 21:08:19 +0000 (16:08 -0500)]
- Mapped state internals have been reworked to allow for a 50% reduction
in callcounts specific to the "expiration" of objects, as in
the "auto expire" feature of :meth:`.Session.commit` and
for :meth:`.Session.expire_all`, as well as in the "cleanup" step
which occurs when object states are garbage collected.
fixes #3307
Mike Bayer [Mon, 9 Feb 2015 20:29:14 +0000 (15:29 -0500)]
- A warning is emitted when :func:`.cast` is used with the MySQL
dialect on a type where MySQL does not support CAST; MySQL only
supports CAST on a subset of datatypes. SQLAlchemy has for a long
time just omitted the CAST for unsupported types in the case of
MySQL. While we don't want to change this now, we emit a warning
to show that it's taken place. A warning is also emitted when
a CAST is used with an older MySQL version (< 4) that doesn't support
CAST at all, it's skipped in this case as well.
fixes #3237
Mike Bayer [Mon, 9 Feb 2015 19:58:26 +0000 (14:58 -0500)]
- Literal values within a :class:`.DefaultClause`, which is invoked
when using the :paramref:`.Column.server_default` parameter, will
now be rendered using the "inline" compiler, so that they are rendered
as-is, rather than as bound parameters.
fixes #3087
Kai Groner [Mon, 26 Jan 2015 19:49:40 +0000 (14:49 -0500)]
Partial index support with sqlite dialects.
From https://www.sqlite.org/partialindex.html
> Partial indexes have been supported in SQLite since version 3.8.0.
Reflection does not expose the predicate of partial indexes. The
postgresql dialect does detect such indexes and issue a warning. I
looked into matching this level of support, but the sqlite pragma
index_info does not expose the predicate. Getting this data would
probably require parsing the CREATE INDEX statement from sqlite_master.
Mike Bayer [Sun, 25 Jan 2015 23:22:00 +0000 (18:22 -0500)]
- remove the clever approach w/ dialect events, and remove the need
for a for-loop through an empty tuple. we add one more local flag
to handle the logic without repetition of dialect.do_execute()
calls.
Mike Bayer [Sun, 25 Jan 2015 22:53:41 +0000 (17:53 -0500)]
- remove context-specific post-crud logic from Connection and inline post-crud
logic to some degree in DefaultExecutionContext. In particular
we are removing post_insert() which doesn't appear to be used
based on a survey of prominent third party dialects. Callcounts
aren't added to existing execute profiling tests and inserts might be
a little better.
- simplify the execution_options join in DEC. Callcounts don't
appear affected.
Mike Bayer [Tue, 20 Jan 2015 16:37:13 +0000 (11:37 -0500)]
- Added new user-space accessors for viewing transaction isolation
levels; :meth:`.Connection.get_isolation_level`,
:attr:`.Connection.default_isolation_level`.
- enhance documentation inter-linkage between new accessors,
existing isolation_level parameters, as well as in
the dialect-level methods which should be fully covered
by Engine/Connection level APIs now.
Mike Bayer [Mon, 19 Jan 2015 22:55:23 +0000 (17:55 -0500)]
- The primary :class:`.Mapper` of a :class:`.Query` is now passed to the
:meth:`.Session.get_bind` method when calling upon
:meth:`.Query.count`, :meth:`.Query.update`, :meth:`.Query.delete`,
as well as queries against mapped columns,
:obj:`.column_property` objects, and SQL functions and expressions
derived from mapped columns. This allows sessions that rely upon
either customized :meth:`.Session.get_bind` schemes or "bound" metadata
to work in all relevant cases.
fixes #3227 fixes #3242 fixes #1326
Mike Bayer [Sun, 18 Jan 2015 02:36:52 +0000 (21:36 -0500)]
- fix a regression from ref #3178, where dialects that don't actually support
sane multi rowcount (e.g. pyodbc) would fail on multirow update. add
a test that mocks this breakage into plain dialects
Mike Bayer [Sat, 17 Jan 2015 01:03:33 +0000 (20:03 -0500)]
- Custom dialects that implement :class:`.GenericTypeCompiler` can
now be constructed such that the visit methods receive an indication
of the owning expression object, if any. Any visit method that
accepts keyword arguments (e.g. ``**kw``) will in most cases
receive a keyword argument ``type_expression``, referring to the
expression object that the type is contained within. For columns
in DDL, the dialect's compiler class may need to alter its
``get_column_specification()`` method to support this as well.
The ``UserDefinedType.get_col_spec()`` method will also receive
``type_expression`` if it provides ``**kw`` in its argument
signature.
fixes #3074
Mike Bayer [Fri, 16 Jan 2015 23:03:45 +0000 (18:03 -0500)]
- Fixed bug where Postgresql dialect would fail to render an
expression in an :class:`.Index` that did not correspond directly
to a table-bound column; typically when a :func:`.text` construct
was one of the expressions within the index; or could misinterpret the
list of expressions if one or more of them were such an expression.
fixes #3174
Mike Bayer [Tue, 13 Jan 2015 22:04:35 +0000 (17:04 -0500)]
- The "wildcard" loader options, in particular the one set up by
the :func:`.orm.load_only` option to cover all attributes not
explicitly mentioned, now takes into account the superclasses
of a given entity, if that entity is mapped with inheritance mapping,
so that attribute names within the superclasses are also omitted
from the load. Additionally, the polymorphic discriminator column
is unconditionally included in the list, just in the same way that
primary key columns are, so that even with load_only() set up,
polymorphic loading of subtypes continues to function correctly.
fixes #3287
Mike Bayer [Tue, 13 Jan 2015 19:33:33 +0000 (14:33 -0500)]
- The multi-values version of :meth:`.Insert.values` has been
repaired to work more usefully with tables that have Python-
side default values and/or functions, as well as server-side
defaults. The feature will now work with a dialect that uses
"positional" parameters; a Python callable will also be
invoked individually for each row just as is the case with an
"executemany" style invocation; a server- side default column
will no longer implicitly receive the value explicitly
specified for the first row, instead refusing to invoke
without an explicit value. fixes #3288