trigger mapper compilation on class attribute access

Issue #758 resolved
jek created an issue

The 0.4 properties-as-columns/comparables feature allows new idioms that may be used before mappers are compiled:

mapper(MyClass, table1)

# prepare some expressions and selects...
criteria_1 = MyClass.kind.in_('a', 'b', 'c')
sel_1 = select([MyClass.id](MyClass.id), criteria_1)

Mappers could perhaps install trigger stubs pre-compilation, something like:

class MapperPropertyStub(object):
    def __init__(self, key):
        self.key = key
    def __get__(self, obj, cls):
        assert not obj
        compile_mappers()
        return getattr(cls, self.key)

Comments (6)

  1. jek reporter

    This may not be feasible without an enormous amount of complexity and overhead- the final list of class properties isn't known until compilation time, plus backrefs...

  2. Mike Bayer repo owner

    we're probably going to have to go with a solution that at least does the column and relation based refs, not including backrefs to start with. in fact its probably going to involve actually placing the InstrumentedAttributes on the classes immediately. there might be some nice simplifications that come out of this effort; the "compile everything later" idea grew out of older versions of the ORM that had a more complicated system of operation regarding relations.

  3. Mike Bayer repo owner

    yeah...i think something here is possible but it requires a big refactoring of how the compile process works, mostly because of inheritance - to get the full list of properties on a class, you need to do all the superclass mappers, etc. some initial attempts almost got it working but its going to be a little more tricky than that.

  4. Mike Bayer repo owner

    OK i have the whole thing working in e92d5cff7ed2a26b119ddae8fdef856c4274c297. I almost think we can close the ticket here, theres a little bit of an issue with the test suite leaving "compileattrs" lying around in some cases which may or may not be a problem, also will need to see if the userbase can handle defining inheriting mappers in inheritance order, which is the main side effect of how mapper compilation was simplified.

  5. Log in to comment