stefanofontanelli/ColanderAlchemy — pull request #55 by davidjb (2014-04-04 07:38:45+00:00)
Title: Fix relationships

SQLAlchemy relationships map to a ``Sequence`` of ``Mapping``s in Colander, being two separate Colander nodes. Previous to [this change](https://github.com/stefanofontanelli/ColanderAlchemy/commit/f96d7e80e214ce3d87689eea62063894bf93c55d), the behaviour was such that ColandarAlchemy settings on a Relationship would be applied to the ``Sequence`` object only, meaning the underlying ``Mapping`` could be configured independently (or left alone to use defaults). However, recent changes in [that commit](https://github.com/stefanofontanelli/ColanderAlchemy/commit/f96d7e80e214ce3d87689eea62063894bf93c55d#diff-6907929d41641a88a25cf5f4c10a3848R479) now cause all settings configured on a relationship (eg on the ``Sequence``) to be applied to the underlying ``Mapping`` node as well. This means that title, description, validator, preparer and any other arbitrary attributes (like widget for Deform) get inherited, which breaks things.

For example, I have this:
```
def has_unique_addresses(node, value):
# step through values
...

class Person(Base):
address = relationship('Address', info={'colanderalchemy': {widget: SequenceWidget(orderable=True), validator=has_unique_addresses})

class Address(Base):
# Can customise CA settings using __colanderalchemy_config__ here
number = Column(String)
street = Column(String)
...
```

Before the change, the above would work as expected, customising the widget and validator for the Sequence only, leaving the Mapping to use the defaults. However, now, the settings from the relationship (drawn into ``kwargs`` in the above-linked code via ``declarative_overrides`` at line 448) are applied to the Mapping when the schema is constructed (line 463), as well as applied to the outer Sequence (line 466). Thus, in the above example, the Mapping ends up with settings that can only work for the Sequence, and thus break the usage of the schema.

My suggestion would be to only apply the ``declarative_overrides`` to the "outer" Sequence node, which is what this pull request does. I can add formal tests as required if you agree with the idea; in my local testing, this restores I'd expect as the correct behaviour.