Mike Bayer [Fri, 28 Mar 2014 20:32:11 +0000 (16:32 -0400)]
- Fixed ORM bug where changing the primary key of an object, then marking
it for DELETE would fail to target the correct row for DELETE.
Then to compound matters, basic "number of rows matched" checks were
not being performed. Both issues are fixed, however note that the
"rows matched" check requires so-called "sane multi-row count"
functionality; the DBAPI's executemany() method must count up the
rows matched by individual statements and SQLAlchemy's dialect must
mark this feature as supported, currently applies to some mysql dialects,
psycopg2, sqlite only. fixes #3006
- Enabled "sane multi-row count" checking for the psycopg2 DBAPI, as
this seems to be supported as of psycopg2 2.0.9.
Mike Bayer [Fri, 28 Mar 2014 14:49:37 +0000 (10:49 -0400)]
- Added support to automap for the case where a relationship should
not be created between two classes that are in a joined inheritance
relationship, for those foreign keys that link the subclass back to
the superclass.
fixes #3004
Mike Bayer [Fri, 28 Mar 2014 00:38:46 +0000 (20:38 -0400)]
- Fixed a very old behavior where the lazy load emitted for a one-to-many
could inappropriately pull in the parent table, and also return results
inconsistent based on what's in the parent table, when the primaryjoin
includes some kind of discriminator against the parent table, such
as ``and_(parent.id == child.parent_id, parent.deleted == False)``.
While this primaryjoin doesn't make that much sense for a one-to-many,
it is slightly more common when applied to the many-to-one side, and
the one-to-many comes as a result of a backref.
Loading rows from ``child`` in this case would keep ``parent.deleted == False``
as is within the query, thereby yanking it into the FROM clause
and doing a cartesian product. The new behavior will now substitute
the value of the local "parent.deleted" for that parameter as is
appropriate. Though typically, a real-world app probably wants to use a
different primaryjoin for the o2m side in any case.
fixes #2948
Mike Bayer [Thu, 27 Mar 2014 23:43:15 +0000 (19:43 -0400)]
- Improved the check for "how to join from A to B" such that when
a table has multiple, composite foreign keys targeting a parent table,
the :paramref:`.relationship.foreign_keys` argument will be properly
interpreted in order to resolve the ambiguity; previously this condition
would raise that there were multiple FK paths when in fact the
foreign_keys argument should be establishing which one is expected.
fixes #2965
Mike Bayer [Thu, 27 Mar 2014 23:18:06 +0000 (19:18 -0400)]
- Tweaked the settings for mysql-connector-python; in Py2K, the
"supports unicode statements" flag is now False, so that SQLAlchemy
will encode the *SQL string* (note: *not* the parameters)
to bytes before sending to the database. This seems to allow
all unicode-related tests to pass for mysql-connector, including those
that use non-ascii table/column names, as well as some tests for the
TEXT type using unicode under cursor.executemany().
- other mysql-connector fixes; latest version seems to do better on
function call counts
Mike Bayer [Wed, 26 Mar 2014 20:31:52 +0000 (16:31 -0400)]
- work on fixing some race-condition failures:
1. make sure pool._invalidate() sets the timestamp up before
invalidating the target connection. we can otherwise show how the
conn.invalidate() + pool._invalidate() can lead to an extra connection
being made.
2. to help with that, soften up the check on connection.invalidate()
when connection is already closed. a warning is fine here
3. add a mutex to test_max_overflow() when we connect, because the way
we're using mock depends on an iterator, that needs to be synchronized
Mike Bayer [Wed, 26 Mar 2014 19:18:29 +0000 (15:18 -0400)]
- rework memusage tests so that it only runs five iterations at a time, if it sees success within
that period, it's done. memusage tests have become very slow
Mike Bayer [Tue, 25 Mar 2014 16:26:42 +0000 (12:26 -0400)]
- Fixed regression caused by release 0.8.5 / 0.9.3's compatibility
enhancements where index reflection on Postgresql versions specific
to only the 8.1, 8.2 series again
broke, surrounding the ever problematic int2vector type. While
int2vector supports array operations as of 8.1, apparently it only
supports CAST to a varchar as of 8.3.
fix #3000
Mike Bayer [Mon, 24 Mar 2014 14:22:39 +0000 (10:22 -0400)]
- Added some new event mechanics for dialect-level events; the initial
implementation allows an event handler to redefine the specific mechanics
by which an arbitrary dialect invokes execute() or executemany() on a
DBAPI cursor. The new events, at this point semi-public and experimental,
are in support of some upcoming transaction-related extensions.
Mike Bayer [Sat, 22 Mar 2014 23:55:00 +0000 (19:55 -0400)]
- Fixed regression from 0.8.3 as a result of :ticket:`2818`
where :meth:`.Query.exists` wouldn't work on a query that only
had a :meth:`.Query.select_from` entry but no other entities.
re: #2818 fixes #2995
Mike Bayer [Sat, 22 Mar 2014 23:34:18 +0000 (19:34 -0400)]
- An event listener can now be associated with a :class:`.Engine`,
after one or more :class:`.Connection` objects have been created
(such as by an orm :class:`.Session` or via explicit connect)
and the listener will pick up events from those connections.
Previously, performance concerns pushed the event transfer from
:class:`.Engine` to :class:`.Connection` at init-time only, but
we've inlined a bunch of conditional checks to make this possible
without any additional function calls. fixes #2978
Mike Bayer [Sat, 22 Mar 2014 23:02:37 +0000 (19:02 -0400)]
- restore the old behavior of the connection pool replacing itself just
within userland engine.dispose(); as some SQLA tests already failed when the replace step
was removed, due to those conns still being referenced, it's likely this will
create surprises for all those users that incorrectly use dispose()
and it's not really worth dealing with. This doesn't affect the change
we made for ref: #2985.
Mike Bayer [Sat, 22 Mar 2014 22:45:39 +0000 (18:45 -0400)]
- A major improvement made to the mechanics by which the :class:`.Engine`
recycles the connection pool when a "disconnect" condition is detected;
instead of discarding the pool and explicitly closing out connections,
the pool is retained and a "generational" timestamp is updated to
reflect the current time, thereby causing all existing connections
to be recycled when they are next checked out. This greatly simplifies
the recycle process, removes the need for "waking up" connect attempts
waiting on the old pool and eliminates the race condition that many
immediately-discarded "pool" objects could be created during the
recycle operation. fixes #2985
Mike Bayer [Sat, 22 Mar 2014 22:22:17 +0000 (18:22 -0400)]
- Added new datatype :class:`.oracle.DATE`, which is a subclass of
:class:`.DateTime`. As Oracle has no "datetime" type per se,
it instead has only ``DATE``, it is appropriate here that the
``DATE`` type as present in the Oracle dialect be an instance of
:class:`.DateTime`. This issue doesn't change anything as far as
the behavior of the type, as data conversion is handled by the
DBAPI in any case, however the improved subclass layout will help
the use cases of inspecting types for cross-database compatibility.
Also removed uppercase ``DATETIME`` from the Oracle dialect as this
type isn't functional in that context. fixes #2987
Mike Bayer [Sat, 22 Mar 2014 21:31:50 +0000 (17:31 -0400)]
- Adjusted ``setup.py`` file to support the possible future
removal of the ``setuptools.Feature`` extension from setuptools.
If this keyword isn't present, the setup will still succeed
with setuptools rather than falling back to distutils. C extension
building can be disabled now also by setting the
DISABLE_SQLALCHEMY_CEXT environment variable. This variable works
whether or not setuptools is even available. fixes #2986
- using platform.python_implementation() in setup.py to detect CPython.
I've tested this function on OSX and linux on Python 2.6 through 3.4,
including 3.1, 3.2, 3.3.
Unfortunately, on OSX + 3.2 only, it seems to segfault. I've tried
installing 3.2.5 from the python.org .dmg, building it from source,
and also blew away the whole 3.2 directory, something seems to be wrong
with the "platform" module on that platform only, and there's also no
issue on bugs.python.org; however, I'm going with
it anyway. If someone is using 3.2 on OSX they really should be upgrading.
Mike Bayer [Fri, 21 Mar 2014 02:46:23 +0000 (22:46 -0400)]
- reword the paragraph which talks about web framework integration for sessions:
1. fix the typo in the paragraph, fixes #2998
2. as zope-sqlalchemy only provides transaction integration and not session scoping,
dial back the language here as people are probably using scoped_session with pyramid anyway
3. as I'm going to again start recommending people don't cling to flask-sqlalchemy so hard,
take out the word "strongly" from the recommendation.
4. as flask is the only framework I can think of that actually has an explicit SQLAlchemy
layer that handles setting up scoped_session, take out the word "most", now it's "some web frameworks"
(by which it means "only flask...and flask-sqlalchemy is probably not worth using anyway")
Mike Bayer [Wed, 19 Mar 2014 17:03:44 +0000 (13:03 -0400)]
- The :meth:`.ConnectionEvents.after_cursor_execute` event is now
emitted for the "_cursor_execute()" method of :class:`.Connection`;
this is the "quick" executor that is used for things like
when a sequence is executed ahead of an INSERT statement, as well as
for dialect startup checks like unicode returns, charset, etc.
the :meth:`.ConnectionEvents.before_cursor_execute` event was already
invoked here. The "executemany" flag is now always set to False
here, as this event always corresponds to a single execution.
Previously the flag could be True if we were acting on behalf of
an executemany INSERT statement.
Mike Bayer [Wed, 19 Mar 2014 15:09:38 +0000 (11:09 -0400)]
- Fixed bug in mutable extension as well as
:func:`.attributes.flag_modified` where the change event would not be
propagated if the attribute had been reassigned to itself.
fixes #2997
Mike Bayer [Mon, 17 Mar 2014 20:25:51 +0000 (16:25 -0400)]
- Improved an error message which would occur if a query() were made
against a non-selectable, such as a :func:`.literal_column`, and then
an attempt was made to use :meth:`.Query.join` such that the "left"
side would be determined as ``None`` and then fail. This condition
is now detected explicitly.
Roman Podoliaka [Tue, 11 Mar 2014 00:34:42 +0000 (17:34 -0700)]
Remove tables from metadata when autoload fails
If autoloading of a table fails, don't register it in a metadata
instance. It seems that the original behaviour was accidentally
changed in f6198d9abf453182f4b111e0579a7a4ef1614e79, restore it.
Mike Bayer [Wed, 12 Mar 2014 21:33:03 +0000 (17:33 -0400)]
- Added a new feature :func:`.schema.conv`, the purpose of which is to
mark a constraint name as already having had a naming convention applied.
This token will be used by Alembic migrations as of Alembic 0.6.4
in order to render constraints in migration scripts with names marked
as already having been subject to a naming convention.
re: #2991
Mike Bayer [Wed, 12 Mar 2014 19:09:48 +0000 (15:09 -0400)]
:paramref:`.MetaData.naming_convention` feature will now also
apply to :class:`.CheckConstraint` objects that are associated
directly with a :class:`.Column` instead of just on the
:class:`.Table`.
Mike Bayer [Wed, 12 Mar 2014 18:46:55 +0000 (14:46 -0400)]
- Fixed bug in new :paramref:`.MetaData.naming_convention` feature
where the name of a check constraint making use of the
`"%(constraint_name)s"` token would get doubled up for the
constraint generated by a boolean or enum type, and overall
duplicate events would cause the `"%(constraint_name)s"` token
to keep compounding itself.
fixes #2991
Mike Bayer [Tue, 11 Mar 2014 16:39:00 +0000 (12:39 -0400)]
- A warning is emitted if the :meth:`.MapperEvents.before_configured`
or :meth:`.MapperEvents.after_configured` events are applied to a
specific mapper or mapped class, as the events are only invoked
for the :class:`.Mapper` target at the general level.
Mike Bayer [Tue, 11 Mar 2014 16:27:10 +0000 (12:27 -0400)]
- Added a new keyword argument ``once=True`` to :func:`.event.listen`
and :func:`.event.listens_for`. This is a convenience feature which
will wrap the given listener such that it is only invoked once.
Mike Bayer [Thu, 6 Mar 2014 16:57:54 +0000 (11:57 -0500)]
- cx_oracle test for "unicode returns" needs to be cx_oracle only,
and also will fail on py3k.
- enhance exclusions so that a requirement attribute can be passed
to fails_if/skip_if.
- fix coverage docs to mention pytest.
Mike Bayer [Wed, 5 Mar 2014 23:14:09 +0000 (18:14 -0500)]
- Fixed small issue in :class:`.SingletonThreadPool` where the current
connection to be returned might get inadvertently cleaned out during
the "cleanup" process. Patch courtesy jd23.
Mike Bayer [Mon, 3 Mar 2014 20:55:17 +0000 (15:55 -0500)]
- Support has been added for pytest to run tests. This runner
is currently being supported in addition to nose, and will likely
be preferred to nose going forward. The nose plugin system used
by SQLAlchemy has been split out so that it works under pytest as
well. There are no plans to drop support for nose at the moment
and we hope that the test suite itself can continue to remain as
agnostic of testing platform as possible. See the file
README.unittests.rst for updated information on running tests
with pytest.
The test plugin system has also been enhanced to support running
tests against mutiple database URLs at once, by specifying the ``--db``
and/or ``--dburi`` flags multiple times. This does not run the entire test
suite for each database, but instead allows test cases that are specific
to certain backends make use of that backend as the test is run.
When using pytest as the test runner, the system will also run
specific test suites multiple times, once for each database, particularly
those tests within the "dialect suite". The plan is that the enhanced
system will also be used by Alembic, and allow Alembic to run
migration operation tests against multiple backends in one run, including
third-party backends not included within Alembic itself.
Third party dialects and extensions are also encouraged to standardize
on SQLAlchemy's test suite as a basis; see the file README.dialects.rst
for background on building out from SQLAlchemy's test platform.
Mike Bayer [Sun, 2 Mar 2014 18:59:06 +0000 (13:59 -0500)]
- get util.get_callable_argspec() to be completely bulletproof for 2.6-3.4,
methods, classes, builtins, functools.partial(), everything known so far
- use get_callable_argspec() within ColumnDefault._maybe_wrap_callable, re: #2979
Mike Bayer [Sun, 2 Mar 2014 15:39:48 +0000 (10:39 -0500)]
- Fixed some test/feature failures occurring in Python 3.4,
in particular the logic used to wrap "column default" callables
wouldn't work properly for Python built-ins.
fixes #2979
Mike Bayer [Fri, 28 Feb 2014 23:50:18 +0000 (18:50 -0500)]
- dont create a self-ref FK if test suite marked as not supporting self ref
- break out reflection of views to support view column reflection separately
from view definition
Mike Bayer [Fri, 28 Feb 2014 19:15:13 +0000 (14:15 -0500)]
- Added a new option to :paramref:`.relationship.innerjoin` which is
to specify the string ``"nested"``. When set to ``"nested"`` as opposed
to ``True``, the "chaining" of joins will parenthesize the inner join on the
right side of an existing outer join, instead of chaining as a string
of outer joins. This possibly should have been the default behavior
when 0.9 was released, as we introduced the feature of right-nested
joins in the ORM, however we are keeping it as a non-default for now
to avoid further surprises.
fixes #2976
Mike Bayer [Fri, 28 Feb 2014 00:54:49 +0000 (19:54 -0500)]
- Fixed bug in :func:`.tuple_` construct where the "type" of essentially
the first SQL expression would be applied as the "comparison type"
to a compared tuple value; this has the effect in some cases of an
inappropriate "type coersion" occurring, such as when a tuple that
has a mix of String and Binary values improperly coerces target
values to Binary even though that's not what they are on the left
side. :func:`.tuple_` now expects heterogeneous types within its
list of values.
fixes #2977
Mike Bayer [Thu, 27 Feb 2014 18:29:59 +0000 (13:29 -0500)]
- Fixed a regression in association proxy caused by :ticket:`2810` which
caused a user-provided "getter" to no longer receive values of ``None``
when fetching scalar values from a target that is non-present. The
check for None introduced by this change is now moved into the default
getter, so a user-provided getter will also again receive values of
None.
re: #2810
Mike Bayer [Thu, 27 Feb 2014 00:27:22 +0000 (19:27 -0500)]
- Removed stale names from ``sqlalchemy.orm.interfaces.__all__`` and
refreshed with current names, so that an ``import *`` from this
module again works.
fixes #2975