Mike Bayer [Sun, 11 Jan 2009 23:37:19 +0000 (23:37 +0000)]
NotSupportedError is a DBAPI wrapper which takes four args and is expected to originate from the DBAPI layer.
Moved those error throws to CompileError/InvalidRequestError.
Mike Bayer [Sun, 11 Jan 2009 22:41:20 +0000 (22:41 +0000)]
- 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.
Michael Trier [Sun, 11 Jan 2009 19:15:30 +0000 (19:15 +0000)]
Modified the do_begin handling in mssql to use the Cursor not the Connection.
This corrects a problem where we were trying to call execute on the Connection
object instead of against the cursor. This is supported on pyodbc but not in
the DBAPI. Overrode the behavior in pymssql to not do special do_begin
processing on that dialect.
Mike Bayer [Tue, 6 Jan 2009 04:30:11 +0000 (04:30 +0000)]
- query.join() raises an error when the target of the join
doesn't match the property-based attribute - while it's
unlikely anyone is doing this, the SQLAlchemy author was
guilty of this particular loosey-goosey behavior.
Michael Trier [Mon, 5 Jan 2009 22:05:51 +0000 (22:05 +0000)]
mssql date / time refactor.
- Added new MSSmallDateTime, MSDateTime2, MSDateTimeOffset, MSTime types
- Refactored the Date/Time types. The smalldatetime data type no longer
truncates to a date only, and will now be mapped to the MSSmallDateTime
type. Closes #1254.
Mike Bayer [Mon, 5 Jan 2009 19:23:56 +0000 (19:23 +0000)]
- property.of_type() is now recognized on a single-table
inheriting target, when used in the context of
prop.of_type(..).any()/has(), as well as
query.join(prop.of_type(...)).
Mike Bayer [Mon, 5 Jan 2009 15:34:09 +0000 (15:34 +0000)]
- Generalized the IdentityManagedState._instance_dict() callable
to the IdentityMap class so that Weak/StrongInstanceDict both
have the same behavior wrt the state referencing the map
- Fixed bug when using weak_instance_map=False where modified
events would not be intercepted for a flush(). [ticket:1272]
Mike Bayer [Sat, 3 Jan 2009 22:15:38 +0000 (22:15 +0000)]
added teardown_instance() to complement setup_instance().
Based on the instance/class agnostic behavior of ClassManager, this might be the best we can
do regarding [ticket:860]
Mike Bayer [Sat, 3 Jan 2009 20:52:34 +0000 (20:52 +0000)]
- query.order_by() accepts None which will remove any pending
order_by state from the query, as well as cancel out any
mapper/relation configured ordering. This is primarily useful
for overriding the ordering specified on a dynamic_loader().
[ticket:1079]
Michael Trier [Sat, 3 Jan 2009 03:59:49 +0000 (03:59 +0000)]
Excluded another failing test from the mssql dialect.
MSSQL doesn't allow ON UPDATE for self-referential keys. The tree of cascading
referential actions must only have one path to a particular table on the
cascading referential actions tree.
Mike Bayer [Sat, 3 Jan 2009 02:42:34 +0000 (02:42 +0000)]
- Fixed some deep "column correspondence" issues which could
impact a Query made against a selectable containing
multiple versions of the same table, as well as
unions and similar which contained the same table columns
in different column positions at different levels.
[ticket:1268]
Mike Bayer [Fri, 2 Jan 2009 21:24:17 +0000 (21:24 +0000)]
- mysql, postgres: "%" signs in text() constructs are automatically escaped to "%%".
Because of the backwards incompatible nature of this change,
a warning is emitted if '%%' is detected in the string. [ticket:1267]
Mike Bayer [Fri, 2 Jan 2009 19:45:05 +0000 (19:45 +0000)]
- sqlalchemy.sql.expression.Function is now a public
class. It can be subclassed to provide user-defined
SQL functions in an imperative style, including
with pre-established behaviors. The postgis.py
example illustrates one usage of this.
Mike Bayer [Fri, 2 Jan 2009 18:22:50 +0000 (18:22 +0000)]
- Custom comparator classes used in conjunction with
column_property(), relation() etc. can define
new comparison methods on the Comparator, which will
become available via __getattr__() on the
InstrumentedAttribute. In the case of synonym()
or comparable_property(), attributes are resolved first
on the user-defined descriptor, then on the user-defined
comparator.
Mike Bayer [Sun, 28 Dec 2008 22:32:04 +0000 (22:32 +0000)]
- Added OracleNVarchar type, produces NVARCHAR2, and also
subclasses Unicode so that convert_unicode=True by default.
NVARCHAR2 reflects into this type automatically so
these columns pass unicode on a reflected table with no explicit
convert_unicode=True flags. [ticket:1233]
Mike Bayer [Sun, 28 Dec 2008 21:48:12 +0000 (21:48 +0000)]
- Can pass mapped attributes and column objects as keys
to query.update({}). [ticket:1262]
- Mapped attributes passed to the values() of an
expression level insert() or update() will use the
keys of the mapped columns, not that of the mapped
attribute.
Michael Trier [Sun, 28 Dec 2008 21:07:57 +0000 (21:07 +0000)]
Added in a new MSGenericBinary type.
This maps to the Binary type so it can implement the specialized behavior of
treating length specified types as fixed-width Binary types and non-length
types as an unbound variable length Binary type.
Michael Trier [Sun, 28 Dec 2008 01:46:44 +0000 (01:46 +0000)]
MSSQL refactoring of BINARY type and addition of MSVarBinary and MSImage.
- Added in new types: MSVarBinary and MSImage
- Modified MSBinary to now return BINARY instead of IMAGE. This is a
backwards incompatible change. Closes #1249.
Mike Bayer [Sat, 27 Dec 2008 18:45:41 +0000 (18:45 +0000)]
- Added a mutex for the initial pool creation when
using pool.manage(dbapi). This prevents a minor
case of "dogpile" behavior which would otherwise
occur upon a heavy load startup. [ticket:799]
Mike Bayer [Fri, 26 Dec 2008 05:28:38 +0000 (05:28 +0000)]
- Reflected foreign keys will properly locate
their referenced column, even if the column
was given a "key" attribute different from
the reflected name. This is achieved via a
new flag on ForeignKey/ForeignKeyConstraint
called "link_to_name", if True means the given
name is the referred-to column's name, not its
assigned key.
[ticket:650]
- removed column types from sqlite doc, we
aren't going to list out "implementation" types
since they aren't significant and are less present
in 0.6
- mysql will report on missing reflected foreign
key targets in the same way as other dialects
(we can improve that to be immediate within
reflecttable(), but it should be within
ForeignKeyConstraint()).
- postgres dialect can reflect table with
an include_columns list that doesn't include
one or more primary key columns
Mike Bayer [Wed, 24 Dec 2008 04:47:06 +0000 (04:47 +0000)]
- 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.
Michael Trier [Mon, 22 Dec 2008 20:20:55 +0000 (20:20 +0000)]
Major refactoring of the MSSQL dialect. Thanks zzzeek.
Includes simplifying the IDENTITY handling and the exception handling. Also
includes a cleanup of the connection string handling for pyodbc to favor
the DSN syntax.