selection = api.expected(api.model, selection)
super(Selection, self).__init__(selection=selection, string=string, **kwargs)
+ def _setup(self, env):
+ super(Selection, self)._setup(env)
+ assert self.selection is not None, "Field %s without selection" % self
+
def _setup_related(self, env):
super(Selection, self)._setup_related(env)
# selection must be computed on related field
# transform columns into new-style fields (enables field inheritance)
for name, column in self._columns.iteritems():
if name in self.__dict__:
- _logger.warning("Field %r erasing an existing value", name)
+ _logger.warning("In class %s, field %r overriding an existing value", self, name)
setattr(self, name, column.to_field())
@classmethod
def _add_field(cls, name, field):
""" Add the given `field` under the given `name` in the class """
- field.set_class_name(cls, name)
-
- # add field in _fields (for reflection)
+ # add field as an attribute and in cls._fields (for reflection)
+ if not isinstance(getattr(cls, name, field), Field):
+ _logger.warning("In model %r, field %r overriding existing value", cls._name, name)
+ setattr(cls, name, field)
cls._fields[name] = field
- # add field as an attribute, unless another kind of value already exists
- if isinstance(getattr(cls, name, field), Field):
- setattr(cls, name, field)
- else:
- _logger.warning("In model %r, member %r is not a field", cls._name, name)
+ # basic setup of field
+ field.set_class_name(cls, name)
if field.store:
cls._columns[name] = field.to_column()