Commit Graph

64 Commits

Author SHA1 Message Date
Mike Bayer 1bb9c99ea9 - liberalize list.remove() regexp as recent Pypy versions
format this message differently than cpython
2015-05-24 09:49:14 -04:00
Mike Bayer a3af638e1a - Fixed more regressions caused by NEVER_SET; comparisons
to transient objects with attributes unset would leak NEVER_SET,
and negated_contains_or_equals would do so for any transient
object as the comparison used only the committed value.
Repaired the NEVER_SET cases, fixes #3371, and also made
negated_contains_or_equals() use state_attr_by_column() just
like a non-negated comparison, fixes #3374
2015-04-20 17:38:03 -04:00
Mike Bayer 3209a73b92 - 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
2015-02-18 16:08:19 -05:00
Mike Bayer b36cdefba2 - Fixed bug that affected generally the same classes of event
as that of 🎫`3199`, when the ``named=True`` parameter
would be used.  Some events would fail to register, and others
would not invoke the event arguments correctly, generally in the
case of when an event was "wrapped" for adaption in some other way.
The "named" mechanics have been rearranged to not interfere with
the argument signature expected by internal wrapper functions.
fixes #3197
2014-09-18 17:49:07 -04:00
Mike Bayer 390207e533 - Added new event handlers :meth:.AttributeEvents.init_collection
and :meth:`.AttributeEvents.dispose_collection`, which track when
a collection is first associated with an instance and when it is
replaced.  These handlers supersede the :meth:`.collection.linker`
annotation. The old hook remains supported through an event adapter.
2014-09-07 20:28:19 -04:00
Mike Bayer 5686472f42 - defaultdict benchmarks faster than a namedtuple; OK
- inline the column-based expiration operations as well
2014-08-29 16:28:19 -04:00
Mike Bayer f10eb28d90 - reverse course in #3061 so that we instead no longer set None in the attribute
when we do a get; we return the None as always but we leave the dict blank
and the loader callable still in place.  The case for this implicit get on a pending object is not
super common and there really should be no change in state at all when this
operation proceeds.   This change is more dramatic as it reverses
a behavior SQLA has had since the first release.
fixes #3061
2014-06-23 19:50:23 -04:00
Mike Bayer 752f2e0fc8 - Adjustment to attribute mechanics concerning when a value is
implicitly initialized to None via first access; this action,
which has always resulted in a population of the attribute,
now emits an attribute event just like any other attribute set
operation and generates the same kind of history as one.  Additionally,
many mapper internal operations will no longer implicitly generate
these "None" values when various never-set attributes are checked.
These are subtle behavioral fixes to attribute mechanics which provide
a better solution to the problem of 🎫`3060`, which also
involves recognition of attributes explicitly set to ``None``
vs. attributes that were never set.
fixes #3061
2014-05-29 19:54:51 -04:00
Mike Bayer bc08ee9029 - Fixed a few edge cases which arise in the so-called "row switch"
scenario, where an INSERT/DELETE can be turned into an UPDATE.
In this situation, a many-to-one relationship set to None, or
in some cases a scalar attribute set to None, may not be detected
as a net change in value, and therefore the UPDATE would not reset
what was on the previous row.   This is due to some as-yet
unresovled side effects of the way attribute history works in terms
of implicitly assuming None isn't really a "change" for a previously
un-set attribute.  See also 🎫`3061`. fixes #3060
2014-05-28 20:01:21 -04:00
Alex Gaynor 1caa7fafbd Fix many typos throughout the codebase
Found using: https://github.com/intgr/topy
2014-04-26 13:13:13 -07:00
Mike Bayer b9a2b58dd7 - 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
2014-03-19 11:09:38 -04:00
Mike Bayer 6750c39a4f - 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
2014-03-02 10:39:48 -05:00
Mike Bayer 2b1c8eabb1 - :func:.attributes.get_history() when used with a scalar column-mapped
attribute will now honor the "passive" flag
passed to it; as this defaults to ``PASSIVE_OFF``, the function will
by default query the database if the value is not present.
This is a behavioral change vs. 0.8.  [ticket:2787]
- Added new method :meth:`.AttributeState.load_history`, works like
:attr:`.AttributeState.history` but also fires loader callables.
2013-10-25 13:13:24 -04:00
Mike Bayer 9a49e09d0b - add predictable_gc to a few more tests showing up on pypy 2013-08-04 15:11:17 -04:00
Mike Bayer 550141b14c - The mechanism by which attribute events pass along an
:class:`.AttributeImpl` as an "initiator" token has been changed;
the object is now an event-specific object called :class:`.attributes.Event`.
Additionally, the attribute system no longer halts events based
on a matching "initiator" token; this logic has been moved to be
specific to ORM backref event handlers, which are the typical source
of the re-propagation of an attribute event onto subsequent append/set/remove
operations.  End user code which emulates the behavior of backrefs
must now ensure that recursive event propagation schemes are halted,
if the scheme does not use the backref handlers.   Using this new system,
backref handlers can now peform a
"two-hop" operation when an object is appended to a collection,
associated with a new many-to-one, de-associated with the previous
many-to-one, and then removed from a previous collection.   Before this
change, the last step of removal from the previous collection would
not occur.
[ticket:2789]
2013-07-26 00:01:04 -04:00
Mike Bayer 731a4daf63 A performance fix related to the usage of the :func:.defer option
when loading mapped entities.   The function overhead of applying
a per-object deferred callable to an instance at load time was
significantly higher than that of just loading the data from the row
(note that ``defer()`` is meant to reduce DB/network overhead, not
necessarily function call count); the function call overhead is now
less than that of loading data from the column in all cases.  There
is also a reduction in the number of "lazy callable" objects created
per load from N (total deferred values in the result) to 1 (total
number of deferred cols).
[ticket:2778]
2013-07-13 16:29:07 -04:00
Mike Bayer 806f5a4183 Fixed bug whereby attribute history functions would fail
when an object we moved from "persistent" to "pending"
using the :func:`.make_transient` function, for operations
involving collection-based backrefs.
[ticket:2773]
2013-07-04 20:02:31 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer 75a3f84e5f - Improved checking for an existing backref name conflict during
mapper configuration; will now test for name conflicts on
superclasses and subclasses, in addition to the current mapper,
as these conflicts break things just as much.  This is new for
0.8, but see below for a warning that will also be triggered
in 0.7.11.
- Improved the error message emitted when a "backref loop" is detected,
that is when an attribute event triggers a bidirectional
assignment between two other attributes with no end.
This condition can occur not just when an object of the wrong
type is assigned, but also when an attribute is mis-configured
to backref into an existing backref pair.  Also in 0.7.11.
- A warning is emitted when a MapperProperty is assigned to a mapper
that replaces an existing property, if the properties in question
aren't plain column-based properties.   Replacement of relationship
properties is rarely (ever?) what is intended and usually refers to a
mapper mis-configuration.   Also in 0.7.11.
[ticket:2674]
2013-03-03 13:51:54 -05:00
Mike Bayer 389325099d - fix regression from 0.7 where calling get_history with passive
on a never-set collection would fail; made this act just like
scalars for now and added tests.  I would think that HISTORY_BLANK
would be more appropriate here but it's too late in the game
to mess with that.
2012-10-22 13:54:39 -04:00
Mike Bayer be40b51cb0 getting everything to pass again 2012-09-27 16:33:54 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer df7a3792f5 - add req's for predictable gc 2012-09-05 12:46:28 -04:00
Mike Bayer 9665015708 - [feature] Adding/removing None from a mapped collection
now generates attribute events.  Previously, a None
append would be ignored in some cases.  Related
to [ticket:2229].

- [feature] The presence of None in a mapped collection
now raises an error during flush.   Previously,
None values in collections would be silently ignored.
[ticket:2229]
2012-08-13 11:00:58 -04:00
Mike Bayer daf286fc33 - [bug] Fixed bug whereby user error in related-object
assignment could cause recursion overflow if the
assignment triggered a backref of the same name
as a bi-directional attribute on the incorrect
class to the same target.  An informative
error is raised now.
2012-08-12 20:37:40 -04:00
Mike Bayer e07f4b9837 - [feature] A warning is emitted when a reference
to an instrumented collection is no longer
    associated with the parent class due to
    expiration/attribute refresh/collection
    replacement, but an append
    or remove operation is received on the
    now-detached collection.  [ticket:2476]
2012-08-04 18:32:38 -04:00
Mike Bayer 9c0de7fcf7 - with InstanceState more public, underscore all its methods
that change object state as these aren't intended for public
use.
2012-07-18 16:43:02 -04:00
Mike Bayer 841ea194bd - [removed] The legacy "mutable" system of the
ORM, including the MutableType class as well
as the mutable=True flag on PickleType
and postgresql.ARRAY has been removed.
In-place mutations are detected by the ORM
using the sqlalchemy.ext.mutable extension,
introduced in 0.7.   The removal of MutableType
and associated constructs removes a great
deal of complexity from SQLAlchemy's internals.
The approach performed poorly as it would incur
a scan of the full contents of the Session
when in use. [ticket:2442]
2012-04-23 18:59:17 -04:00
Mike Bayer ff0fb31bf2 - merge attribute flag overhaul for [ticket:2358] 2012-04-23 11:45:06 -04:00
Mike Bayer 2d154b01f1 add tests for #2128 2012-02-26 18:43:36 -05:00
Mike Bayer acc5277a81 - attribute system gets a pop() method.
- remove() on a scalar object will raise if the object
removed is not what was present.
- InstanceState can be pickled if obj() is None; this
to support the other changes in this commit
- only use trackparent flag on attributes if
single_parent or ONETOMANY; otherwise we can skip this
overhead
- attribute hasparent()/sethasparent() check that trackparent
is set, else their usage is invalid
- [bug] Fixed backref behavior when "popping" the
value off of a many-to-one in response to
a removal from a stale one-to-many - the operation
is skipped, since the many-to-one has since
been updated.  [ticket:2315]

- [bug] After some years of not doing this, added
more granularity to the "is X a parent of Y"
functionality, which is used when determining
if the FK on "Y" needs to be "nulled out" as well
as if "Y" should be deleted with delete-orphan
cascade.   The test now takes into account the
Python identity of the parent as well its identity
key, to see if the last known parent of Y is
definitely X.   If a decision
can't be made, a StaleDataError is raised.  The
conditions where this error is raised are fairly
rare, requiring that the previous parent was
garbage collected, and previously
could very well inappropriately update/delete
a record that's since moved onto a new parent,
though there may be some cases where
"silent success" occurred previously that will now
raise in the face of ambiguity.
Expiring "Y" resets the "parent" tracker, meaning
X.remove(Y) could then end up deleting Y even
if X is stale, but this is the same behavior
as before; it's advised to expire X also in that
case.  [ticket:2264]
2011-10-30 15:10:56 -04:00
Mike Bayer f288c06504 - Fixed regression from 0.6 where a get history
operation on some relationship() based attributes
    would fail when a lazyload would emit; this could
    trigger within a flush() under certain conditions.
    [ticket:2224]  Thanks to the user who submitted
    the great test for this.
2011-07-20 18:30:57 -04:00
Mike Bayer 1da499a838 - Added checks inside the UOW to detect the unusual
condition of being asked to UPDATE or DELETE
on a primary key value that contains NULL
in it.  [ticket:2127]

- Some refinements to attribute history.  More
changes are pending possibly in 0.8, but
for now history has been modified such that
scalar history doesn't have a "side effect"
of populating None for a non-present value.
This allows a slightly better ability to
distinguish between a None set and no actual
change, affects [ticket:2127] as well.

- rewriting the history tests in test_attributes to be
individual per operation/assertion.   its a huge job
so this is partial for the moment.
2011-04-10 20:22:11 -04:00
Mike Bayer a645032262 - Some fixes to the state handling regarding
backrefs, typically when autoflush=False, where
the back-referenced collection wouldn't
properly handle add/removes with no net
change.  Thanks to Richard Murri for the
test case + patch.  [ticket:2123]
(also in 0.6.7).
2011-04-07 17:56:01 -04:00
Mike Bayer 7b24e458c7 - move all the comments that got shoved below the fixture grabs back up 2011-03-27 17:19:00 -04:00
Mike Bayer 68a350d462 - remove test.sql._base, test.engine._base, test.orm._base, move those classes to a new test.lib.fixtures module
- move testing.TestBase to test.lib.fixtures
- massive search and replace
2011-03-27 16:27:27 -04:00
Diana Clarke 13242f766e corrected a bunch of spelling typos 2011-02-28 13:17:46 -05:00
Mike Bayer 2a289e915e - fix long lines in test_attributes
- add deprecation warning to get_history() when passed
True or False, convert
- rearrange symbol() so we can get sphinx autodata to work
2011-02-11 17:58:49 -05:00
Mike Bayer ad9b85fa8e - replace all usage of True and False for passive with PASSIVE_NO_INITIALIZE,
PASSIVE_OFF, now expresed as non-boolean symbols
- make "passive" available positionally on all get_history() methods,
call it like that
2011-02-11 15:37:44 -05:00
Mike Bayer e155b7b864 - An exception is raised in the unusual case that an
append or similar event on a collection occurs after
the parent object has been dereferenced, which
prevents the parent from being marked as "dirty"
in the session.  Will commit as a warning in 0.6.
[ticket:2046]
2011-02-10 11:30:23 -05:00
Mike Bayer 350aed3fdb - whitespace removal bonanza 2011-01-02 14:23:42 -05:00
Mike Bayer 426c4356eb - removes the "on_" prefix. 2010-12-30 14:22:43 -05:00
Mike Bayer e9d1b5b8de - added flag to mark any attribute as "modified" 2010-12-23 14:10:14 -05:00
Mike Bayer 29e5a23aee - refactor expire_attributes into two simpler methods 2010-12-21 11:08:12 -05:00
Mike Bayer f7f6fbede5 - remove the need to use LoadDeferredColumns, LoadLazyAttribute in most cases,
these are back to being part of LoaderStrategy
- simplify attribute.get()
- inline the dict get inside of attribute.__get__()
- revert some memoized attrs from InstanceState which are called in almost
all cases regardless
- inlining
2010-12-16 21:08:26 -05:00
Mike Bayer e05c91acaa - callcounts 2010-12-10 18:27:23 -05:00
Mike Bayer 1f9029597c - move topological, queue into util
- move function_named into test.lib.util
- use @decorator for all decorators in test/
2010-12-05 12:51:24 -05:00
Mike Bayer d30678d18d new calling style: event.listen(target, identifier, fn) 2010-12-01 14:10:11 -05:00
Mike Bayer 3c9d2d7b2f - replace GenericBackrefExtension with straight events
- add "backref" argument to register_attribute_impl
2010-11-30 20:25:22 -05:00
Mike Bayer 58b2939433 - sqlalchemy.test and nose plugin moves back to being entirely
outside of "sqlalchemy" and under "test/".

Rationale:

- coverage plugin works without issue, without need for an awkward
additional package install
- command line for "nosetests" isn't polluted with SQLAlchemy options

[ticket:1949]
2010-11-28 14:19:44 -05:00