Skip to content

Handle columns without python_type #27

Closed
@jmcarp

Description

@jmcarp

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?

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