question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when a model contains a column_property

See original GitHub issue
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'>.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sloriacommented, Aug 19, 2019

This is a known issue. I’m not quite sure how to solve this since column_properties can return any type. For now, use an explicit field

    total_tasks = fields.Integer(dump_only=True)
1reaction
jebragecommented, Aug 28, 2018

This works for me.

class FooSchema(ModelSchema):
    moo = ma_fields.Integer(dump_only=True)

    class Meta:
        model = Foo

        fields = (
          Foo.moo.key,
        )

        dump_only = (
            Foo.moo.key,
        )

This seems right as we should only need the property during serialization and dumping. We shouldn’t need it to deserialize and load.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLAlchemy Error in elements.py - ColumnClause nor ...
After digging into the python console and importing the module, I produce this error by trying to print the property of the object....
Read more >
ORM Internals
Tracks state information at the class level. ColumnProperty. Describes an object attribute that corresponds to a table column. CompositeProperty.
Read more >
Solved: Re: Value null to type number error with postgres ...
Hi, What is the column property? ... I have been receiving "Cannot convert value Null to type number " error for a column...
Read more >
The Is Nullable Column Property In Power BI
The new Relationships view (or Modeling view – it seems to have two ... the following error when you try to refresh a...
Read more >
Meta-schema Manager error messages
The column property property is required but it cannot be found. The loading of the schema file cannot continue. GS-11124. Table table already...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found