Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle columns without `python_type` #27

jmcarp opened this issue Sep 21, 2015 · 2 comments


Copy link

commented Sep 21, 2015

To determine the field class to be used for a SQLAlchemy column, we sometimes check its python_type. But some columns, e.g. Postgres TSVECTOR columns, don't have a python_type and raise a NotImplementedError on trying to access. Some possible fixes:

  • Add TSVECTOR to SQLA_TYPE_MAPPING. This would kind of fix the immediate problem I'm running into, but what's the right marshmallow type to use? We could use Str, but that's not exactly right. Also, this doesn't help if other columns are missing python_type, which might or might not be the case.
  • Allow developers to exclude unusual fields from model conversion, e.g. via the Meta.exclude option in marshmallow. This is more flexible but requires developers to understand that they can / should exclude columns that don't convert to fields.
  • Don't raise an exception on failing to convert a column to a field. Possibly add a strict option to fields_for_model, such that ModelConversionErrors are only raised when strict is true. This is also flexible, but allows developers to silence potentially heterogeneous kinds of exceptions.

I'm submitting a patch for the second option, mostly so I can get some unrelated work done, but I think the third also makes sense, and it might not be bad to use both. What do you think @sloria?


This comment has been minimized.

Copy link

commented Sep 21, 2015

I think option 2 is good, though perhaps it should be separate from marshmallow's built-in Meta.exclude, like no_autogenerate? I'm not sure about this yet.

I'm not sure option 3 is necessary if option 2 is implemented. It seems better to always fail loudly if a field isn't generated. This makes it easier to know exactly which fields are included in (de)serialized data.


This comment has been minimized.

Copy link
Contributor Author

commented Sep 22, 2015

Sounds like this is adequately resolved in #28.

@jmcarp jmcarp closed this Sep 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.