You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
To determine the field class to be used for a SQLAlchemy column, we sometimes check its
python_type
. But some columns, e.g. PostgresTSVECTOR
columns, don't have apython_type
and raise aNotImplementedError
on trying to access. Some possible fixes:TSVECTOR
toSQLA_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 useStr
, but that's not exactly right. Also, this doesn't help if other columns are missingpython_type
, which might or might not be the case.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.strict
option tofields_for_model
, such thatModelConversionErrors
are only raised whenstrict
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?
The text was updated successfully, but these errors were encountered: