Commit Graph

413 Commits

Author SHA1 Message Date
Mike Bayer dc7974deae attempt to exlude sqlite 3.5.9 and below, for buildbot failure. not clear which version of sqlite fixes this particular issue 2009-03-08 19:29:56 +00:00
Mike Bayer 3953fe0ad4 some buildbot fixes 2009-03-08 02:35:46 +00:00
Mike Bayer b60185a078 - Declarative will accept a table-bound column as a property
when used in conjunction with __table__, if the column is already
present in __table__.  The column will be remapped to the given
key the same way as when added to the mapper() properties dict.
2009-02-22 19:35:36 +00:00
Mike Bayer 734e02c4f1 - Declarative locates the "inherits" class using a search
through __bases__, to skip over mixins that are local
to subclasses.
2009-02-19 15:48:37 +00:00
Mike Bayer 38c9a5be50 - Declarative will properly interpret the "foreign_keys" argument
on a backref() if it's a string.
2009-02-17 22:09:30 +00:00
Mike Bayer 689a144a71 - Fixed a recursive pickling issue in serializer, triggered
by an EXISTS or other embedded FROM construct.
2009-02-17 12:56:48 +00:00
Mike Bayer 2ab5b4f30c fix errant foreign key 2009-01-17 19:28:46 +00:00
Mike Bayer b996bcff52 - The "clear()", "save()", "update()", "save_or_update()"
Session methods have been deprecated, replaced by
"expunge_all()" and "add()".  "expunge_all()" has also
been added to ScopedSession.
2009-01-17 18:19:29 +00:00
Mike Bayer 3e3f309cf9 - It's an error to add new Column objects to a declarative class
that specified an existing table using __table__.
2009-01-13 15:45:59 +00:00
Mike Bayer b99bdc7cee - Column with no name (as in declarative) won't raise a
NoneType error when it's string output is requsted
(such as in a stack trace).
2009-01-13 15:38:38 +00:00
Mike Bayer 32add82d01 - Can now specify Column objects on subclasses which have no
table of their own (i.e. use single table inheritance).
The columns will be appended to the base table, but only
mapped by the subclass.

- For both joined and single inheriting subclasses, the subclass
will only map those columns which are already mapped on the
superclass and those explicit on the subclass.  Other
columns that are present on the `Table` will be excluded
from the mapping by default, which can be disabled
by passing a blank `exclude_properties` collection to the
`__mapper_args__`.  This is so that single-inheriting
classes which define their own columns are the only classes
to map those columns.   The effect is actually a more organized
mapping than you'd normally get with explicit `mapper()`
calls unless you set up the `exclude_properties` arguments
explicitly.

- docs/tests
2009-01-12 20:36:06 +00:00
Mike Bayer 91001b84c6 mysql/pg sensitive fixes 2009-01-12 00:06:47 +00:00
Mike Bayer 209e888e1b - Concrete inheriting mappers now instrument attributes which are inherited from the superclass, but are not defined for the concrete mapper itself, with an InstrumentedAttribute that issues a descriptive error when accessed. [ticket:1237]
- Added a new `relation()` keyword `back_populates`.  This allows configuation of backreferences using explicit relations. [ticket:781]  This is required when creating bidirectional relations between a hierarchy of concrete mappers and another class. [ticket:1237]
- Test coverage added for `relation()` objects specified on concrete mappers. [ticket:1237]
- A short documentation example added for bidirectional relations specified on concrete mappers. [ticket:1237]
- Mappers now instrument class attributes upon construction with the final InstrumentedAttribute object which remains persistent.  The `_CompileOnAttr`/`__getattribute__()` methodology has been removed.  The net effect is that Column-based mapped class attributes can now be used fully at the class level without invoking a mapper compilation operation, greatly simplifying typical usage patterns within declarative. [ticket:1269]
- Index now accepts column-oriented InstrumentedAttributes (i.e. column-based mapped class attributes) as column arguments.  [ticket:1214]
- Broke up attributes.register_attribute into two separate functions register_descriptor and register_attribute_impl.    The first assembles an InstrumentedAttribute or Proxy descriptor, the second assembles the AttributeImpl inside the InstrumentedAttribute.  register_attribute remains for outside compatibility.  The argument lists have been simplified.
- Removed class_manager argument from all but MutableScalarAttributeImpl (the branch had removed class_ as well but this has been reverted locally to support the serializer extension).
- Mapper's previous construction of _CompileOnAttr now moves to a new MapperProperty.instrument_class() method which is called on all MapperProperty objects at the moment the mapper receives them. All MapperProperty objects now call attributes.register_descriptor within that method to assemble an InstrumentedAttribute object directly.
- InstrumentedAttribute now receives the "property" attribute from the given PropComparator.  The guesswork within the constructor is removed, and allows "property" to serve as a mapper compilation trigger.
- RelationProperty.Comparator now triggers compilation of its parent mapper within a util.memoized_property accessor for the "property" attribute, which is used instead of "prop" (we can probably remove "prop").
- ColumnProperty and similar handle most of their initialization in their __init__ method since they must function fully at the class level before mappers are compiled.
- SynonymProperty and ComparableProperty move their class instrumentation logic to the new instrument_class() method.
- LoaderStrategy objects now add their state to existing InstrumentedAttributes using attributes.register_attribute_impl.  Both column and relation-based loaders instrument in the same way now, with a unique InstrumentedAttribute *and* a unique AttributeImpl for each class in the hierarchy.  attribute.parententity should now be correct in all cases.
- Removed unitofwork.register_attribute, and simpified the _register_attribute methods into a single function in strategies.py.  unitofwork exports the UOWEventHandler extension directly.
- To accomodate the multiple AttributeImpls across a class hierarchy, the sethasparent() method now uses an optional "parent_token" attribute to identify the "parent".  AbstractRelationLoader sends the MapperProperty along to serve as this token.  If the token isn't present (which is only the case in the attributes unit tests), the AttributeImpl is used instead, which is essentially the same as the old behavior.
- Added new ConcreteInheritedProperty MapperProperty.  This is invoked for concrete mappers within _adapt_inherited_property() to accomodate concrete mappers which inherit unhandled attributes from the base class, and basically raises an exception upon access.  [ticket:1237]
- attributes.register_attribute and register_descriptor will now re-instrument an attribute unconditionally without checking for a previous attribute.  Not sure if this is controversial. It's needed so that ConcreteInheritedProperty instrumentation can be overridden by an incoming legit MapperProperty without any complexity.
- Added new UninstrumentedColumnLoader LoaderStrategy.  This is used by the polymorphic_on argument when the given column is not represented within the mapped selectable, as is typical with a concrete scenario which maps to a polymorphic union.  It does not configure class instrumentation, keeping polymorphic_on from getting caught up in the new concrete attribute-checking logic.
- RelationProperty now records its "backref" attributes using a set assigned to `_reverse_property` instead of a scalar.  The `back_populates` keyword allows any number of properties to be involved in a single bidirectional relation.  Changes were needed to RelationProperty.merge(), DependencyProcessor to accomodate for the new multiple nature of this attribute.
- Generalized the methodology used by ManyToManyDP to check for "did the other dependency already handle this direction", building on the `_reverse_property` collection.
- post_update logic within dependency.py moves to use the same methodology as ManyToManyDP so that "did the other dependency do this already" checks are made to be specific to the two dependent instances.
- Caught that RelationProperty.merge() was writing to instance.__dict__ directly (!) - repaired to talk to instance_state.dict.
- Removed needless eager loading example from concrete mapper docs.
- Added test for [ticket:965].
- Added the usual Node class/nodes table to orm/_fixtures.py, but haven't used it for anything yet.   We can potentially update test/orm/query.py to use this fixture.
- Other test/documentation cleanup.
2009-01-11 22:41:20 +00:00
Mike Bayer 7b3b9f559a - 0.5.1 bump
- modernized mapper()/no table exception
- added __tablename__ exception to declarative since ppl keep complaining
2009-01-11 16:45:45 +00:00
Mike Bayer 2876c7e46f - Exceptions raised during compile_mappers() are now
preserved to provide "sticky behavior" - if a hasattr()
call on a pre-compiled mapped attribute triggers a failing
compile and suppresses the exception, subsequent compilation
is blocked and the exception will be reiterated on the
next compile() call.  This issue occurs frequently
when using declarative.
2008-12-24 04:47:06 +00:00
Mike Bayer f2774461d3 fix unittest import 2008-12-21 02:39:45 +00:00
Mike Bayer d76dc73f33 merge the test/ directory from -r5438:5439 of py3k_warnings branch. this gives
us a 2.5-frozen copy of unittest so we're insulated from unittest changes.
2008-12-18 18:11:12 +00:00
Mike Bayer be5d326343 merged -r5299:5438 of py3k warnings branch. this fixes some sqlite py2.6 testing issues,
and also addresses a significant chunk of py3k deprecations.  It's mainly
expicit __hash__ methods.  Additionally, most usage of sets/dicts to store columns uses
util-based placeholder names.
2008-12-18 17:57:15 +00:00
Mike Bayer 75e8350e4d - comparator_factory is accepted by all MapperProperty constructors. [ticket:1149]
- added other unit tests as per [ticket:1149]
- rewrote most of the "joined table inheritance" documentation section, removed badly out of
date "polymorphic_fetch" and "select_table" arguments.
- "select_table" raises a deprecation warning.  converted unit tests to not use it.
- removed all references to "ORDER BY table.oid" from mapping docs.
- renamed PropertyLoader to RelationProperty.  Old symbol remains.
- renamed ColumnProperty.ColumnComparator to ColumnProperty.Comparator.  Old symbol remains.
2008-11-24 01:14:32 +00:00
Mike Bayer 3e486caaab - switched session.save() to session.add() throughout declarative test
- Fixed PendingDeprecationWarning involving order_by
parameter on relation(). [ticket:1226]
- Unit tests still filter pending deprecation warnings but have a commented-out
line to temporarily disable this behavior.  Tests need to be fully converted
before we can turn this on.
2008-11-14 18:57:24 +00:00
Mike Bayer 0148adec30 - Can now use a custom "inherit_condition" in
__mapper_args__ when using declarative.
2008-11-12 15:43:17 +00:00
Mike Bayer c3352e5542 - Fixed bug in Query involving order_by() in conjunction with
multiple aliases of the same class (will add tests in
[ticket:1218])
- Added a new extension sqlalchemy.ext.serializer.  Provides
Serializer/Deserializer "classes" which mirror Pickle/Unpickle,
as well as dumps() and loads().  This serializer implements
an "external object" pickler which keeps key context-sensitive
objects, including engines, sessions, metadata, Tables/Columns,
and mappers, outside of the pickle stream, and can later
restore the pickle using any engine/metadata/session provider.
This is used not for pickling regular object instances, which are
pickleable without any special logic, but for pickling expression
objects and full Query objects, such that all mapper/engine/session
dependencies can be restored at unpickle time.
2008-11-06 23:07:47 +00:00
Mike Bayer a5dfbeedb9 - Improved the behavior of aliased() objects such that they more
accurately adapt the expressions generated, which helps
particularly with self-referential comparisons. [ticket:1171]

- Fixed bug involving primaryjoin/secondaryjoin conditions
constructed from class-bound attributes (as often occurs
when using declarative), which later would be inappropriately
aliased by Query, particularly with the various EXISTS
based comparators.
2008-11-03 02:52:30 +00:00
Mike Bayer f432bd3550 - Fixed exception throw which would occur when string-based
primaryjoin condition was used in conjunction with backref.
2008-09-04 21:26:49 +00:00
Mike Bayer 94c32b19a0 - Fixed bug whereby mapper couldn't initialize if a composite
primary key referenced another table that was not defined
yet [ticket:1161]
2008-09-04 17:44:48 +00:00
Mike Bayer e01e972ac3 - fixed tearDown to reverse sorted table list 2008-08-23 19:38:04 +00:00
Mike Bayer 427ed1966f - fixed a bug in declarative test which was looking for old version of history
- Added "sorted_tables" accessor to MetaData, which returns
Table objects sorted in order of dependency as a list.
This deprecates the MetaData.table_iterator() method.
The "reverse=False" keyword argument has also been
removed from util.sort_tables(); use the Python
'reversed' function to reverse the results.
[ticket:1033]
2008-08-19 21:27:34 +00:00
Mike Bayer d371637af0 - fixed endless loop bug which could occur
within a mapper's deferred load of
inherited attributes.
- declarative initialization of Columns adjusted so that
non-renamed columns initialize in the same way as a non
declarative mapper.   This allows an inheriting mapper
to set up its same-named "id" columns in particular
such that the parent "id" column is favored over the child
column, reducing database round trips when this value
is requested.
2008-08-04 15:21:29 +00:00
Mike Bayer 8df49e7194 descriptive error message raised when string-based relation() expressions inadvertently mistake a PropertyLoader for a ColumnLoader property 2008-08-03 18:39:53 +00:00
Mike Bayer 449b33e059 relation.order_by requires _literal_as_column conversion as well 2008-07-29 19:49:46 +00:00
Mike Bayer 419753f59b - An inheriting class can now override an attribute
inherited from the base class with a plain descriptor,
or exclude an inherited attribute via the
include_properties/exclude_properties collections.
2008-07-20 18:23:44 +00:00
Mike Bayer d56862cbca - Some improvements to the _CompileOnAttr mechanism which
should reduce the probability of "Attribute x was
not replaced during compile" warnings. (this generally
applies to SQLA hackers, like Elixir devs).
2008-07-19 19:23:37 +00:00
Mike Bayer c5141f2981 - Class-bound attributes sent as arguments to
relation()'s remote_side and foreign_keys parameters
are now accepted, allowing them to be used with declarative.
2008-07-19 18:55:11 +00:00
Jason Kirtland 8fa48edbf9 - Removed 2.3 set emulations/enhancements.
(sets.Set-based collections & DB-API returns still work.)
2008-07-15 19:23:52 +00:00
Mike Bayer 5d375cd730 - Declarative supports a __table_args__ class variable, which
is either a dictionary, or tuple of the form
(arg1, arg2, ..., {kwarg1:value, ...}) which contains positional
+ kw arguments to be passed to the Table constructor.
[ticket:1096]
2008-07-09 20:38:35 +00:00
Jason Kirtland c49a7dd910 - Oops, convert @decorator to 2.3 syntax and strengthen raw_append test. 2008-06-19 17:40:13 +00:00
Mike Bayer cd95c479e9 added string argument resolution to relation() in conjunction with declarative for: order_by,
primaryjoin, secondaryjoin, secondary, foreign_keys, and remote_side.
2008-05-26 23:01:05 +00:00
Jason Kirtland 790f3d44d9 - Fixed ORM orphaning bug with _raw_append method
- Promoted _reorder to reorder
- Now horking docstrings of overloaded methods from list
- Added a doctest
2008-05-21 18:31:52 +00:00
Jason Kirtland 3b90b8d772 - 2.3 compat. 2008-05-21 02:49:14 +00:00
Mike Bayer ac934fc533 - renamed query.slice_() to query.slice()
- pulled out DeclarativeMeta.__init__ into its own function, added instrument_declarative()
which will do the "declarative" thing to any class independent of its lineage (for ctheune)
- added "cls" kwarg to declarative_base() allowing user-defined base class for declarative base [ticket:1042]
2008-05-13 20:35:41 +00:00
Jason Kirtland 72dc624bb6 Removed declared_synonym(), pep-8 clean ups. 2008-05-13 18:14:28 +00:00
Lele Gaifax 559af99865 Tag PKs with test_needs_autoincrement on a few test 2008-05-13 09:40:44 +00:00
Mike Bayer 4a6afd469f r4695 merged to trunk; trunk now becomes 0.5.
0.4 development continues at /sqlalchemy/branches/rel_0_4
2008-05-09 16:34:10 +00:00
Jason Kirtland 586e5be1bb Adjusted inplace-binops on set-based collections and association proxies to
more closely follow builtin (2.4+) set semantics.  Formerly any set duck-type
was accepted, now only types or subtypes of set, frozenset or the collection
type itself are accepted.
2008-05-05 21:33:29 +00:00
Mike Bayer 99f02b59af - fixed reentrant mapper compile hang when
a declared attribute is used within ForeignKey,
ie. ForeignKey(MyOtherClass.someattribute)
2008-05-02 18:23:16 +00:00
Mike Bayer e3460573d0 - factored out the logic used by Join to create its join condition
- With declarative, joined table inheritance mappers use a slightly relaxed
function to create the "inherit condition" to the parent
table, so that other foreign keys to not-yet-declared
Table objects don't trigger an error.
2008-05-02 01:02:23 +00:00
Jason Kirtland f035981a66 And a copy.copy() test for the proxy cache. 2008-04-29 18:28:36 +00:00
Jason Kirtland 629d6dc568 - Refresh the cached proxy if the cache was built for a different instance. 2008-04-29 18:22:23 +00:00
Mike Bayer 99ed392267 - declarative_base() takes optional kwarg "mapper", which
is any callable/class/method that produces a mapper,
such as declarative_base(mapper=scopedsession.mapper).
This property can also be set on individual declarative
classes using the "__mapper_cls__" property.
2008-03-29 14:41:41 +00:00
Mike Bayer dde6466660 - already-compiled mappers will still trigger compiles of
other uncompiled mappers when used [ticket:995]
2008-03-23 16:36:47 +00:00