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

Skip introspection on defined fields. #57

Merged
merged 1 commit into from
Feb 22, 2016

Conversation

jmcarp
Copy link
Contributor

@jmcarp jmcarp commented Feb 19, 2016

Some SQLAlchemy columns can't currently be introspected by
marshmallow-sqlalchemy, or can't be introspected in principle. For
example, columns defined using mapped SQL expressions (using
column_property or object_session) don't have types and don't define
a nullable attribute. In these rare cases, users may want to set
custom fields in their schemas. But this isn't currently possible, since
we raise a ModelConversionError when we encounter a column we can't
introspect. This patch skips introspection when the user has explicitly
defined a field in the schema.

Alternatively, we could map NullType to Raw in SQLA_TYPE_MAPPING
and handle properties that don't define nullable, which would allow
users to work with mapped expressions without schema field overrides. I
slightly prefer this approach, since it's a bit more flexible, and
because I don't think it's a bad thing for users to explicitly define
types of mapped expressions.

Probably too much discussion for a rare edge case. Thoughts @sloria?

Some SQLAlchemy columns can't currently be introspected by
marshmallow-sqlalchemy, or can't be introspected in principle. For
example, columns defined using mapped SQL expressions (using
`column_property` or `object_session`) don't have types and don't define
a `nullable` attribute. In these rare cases, users may want to set
custom fields in their schemas. But this isn't currently possible, since
we raise a `ModelConversionError` when we encounter a column we can't
introspect. This patch skips introspection when the user has explicitly
defined a field in the schema.

Alternatively, we could map `NullType` to `Raw` in `SQLA_TYPE_MAPPING`
and handle properties that don't define `nullable`, which would allow
users to work with mapped expressions without schema field overrides. I
slightly prefer this approach, since it's a bit more flexible, and
because I don't think it's a bad thing for users to explicitly define
types of mapped expressions.
@sloria
Copy link
Member

sloria commented Feb 22, 2016

This looks like the right approach. Thanks.

sloria added a commit that referenced this pull request Feb 22, 2016
Skip introspection on defined fields.
@sloria sloria merged commit 961d28b into marshmallow-code:dev Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants