Changeset 422

Show
Ignore:
Timestamp:
12/04/08 17:11:53 (3 years ago)
Author:
ged
Message:

delete Elixir properties as late as possible (ie in setup phase), not right
after they are added. It makes for a less confusing behavior.

Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/entity.py

    r421 r422  
    841841 
    842842    for entity in entities: 
     843        # delete all Elixir properties so that it doesn't interfere with 
     844        # SQLAlchemy. At this point they should have be converted to 
     845        # builders. 
     846        for name, attr in entity.__dict__.items(): 
     847            if isinstance(attr, Property): 
     848                delattr(entity, name) 
     849 
    843850        if entity._descriptor.autosetup: 
    844851            _cleanup_autosetup_triggers(entity) 
  • elixir/trunk/elixir/properties.py

    r383 r422  
    127127        entity._descriptor.builders.append(self) 
    128128 
    129         # delete the original attribute so that it doesn't interfere with 
    130         # SQLAlchemy. Note that getattr and delattr are not symmetrical: 
    131         # getattr look up in parent classes, while delattr must be called on 
    132         # the exact class holding the attribute. 
    133         if name in entity.__dict__: 
    134             delattr(entity, name) 
    135  
    136129    def __repr__(self): 
    137130        return "Property(%s, %s)" % (self.name, self.entity) 
  • elixir/trunk/tests/test_properties.py

    r349 r422  
    1414    def teardown(self): 
    1515        cleanup_all(True) 
     16 
     17    def test_lifecycle(self): 
     18        class A(Entity): 
     19            name = Field(String(20)) 
     20 
     21        assert isinstance(A.name, Field) 
     22 
     23        setup_all() 
     24 
     25        assert not isinstance(A.name, Field) 
    1626 
    1727    def test_generic_property(self):