Skip to content

Error when a model contains a column_property #97

Description

@ThiefMaster
from marshmallow_sqlalchemy import ModelSchema
from sqlalchemy import *
from sqlalchemy.ext.declarative import declared_attr, declarative_base
from sqlalchemy.orm import *

Base = declarative_base()


class Foo(Base):
    __tablename__ = 'foo'
    id = Column(Integer, primary_key=True)

    @declared_attr
    def moo(self):
        return column_property(select([1337]))


e = create_engine('sqlite:///')
Base.metadata.create_all(e)
s = Session(e)

s.add(Foo())
s.commit()

foo = s.query(Foo).first()
print foo.moo


class FooSchema(ModelSchema):
    class Meta:
        model = Foo

Traceback

Traceback (most recent call last):
  File "satest.py", line 29, in <module>
    class FooSchema(ModelSchema):
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow/schema.py", line 116, in __new__
    dict_cls=dict_cls
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/schema.py", line 60, in get_declared_fields
    declared_fields = mcs.get_fields(converter, opts, base_fields, dict_cls)
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/schema.py", line 94, in get_fields
    dict_cls=dict_cls,
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/convert.py", line 105, in fields_for_model
    field = base_fields.get(prop.key) or self.property2field(prop)
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/convert.py", line 125, in property2field
    field_class = field_class or self._get_field_class_for_property(prop)
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/convert.py", line 186, in _get_field_class_for_property
    field_cls = self._get_field_class_for_column(column)
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/convert.py", line 153, in _get_field_class_for_column
    return self._get_field_class_for_data_type(column.type)
  File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/marshmallow_sqlalchemy/convert.py", line 178, in _get_field_class_for_data_type
    'Could not find field column of type {0}.'.format(types[0]))
marshmallow_sqlalchemy.exceptions.ModelConversionError: Could not find field column of type <class 'sqlalchemy.sql.sqltypes.NullType'>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions