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

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?

Skip introspection on defined fields.
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

This comment has been minimized.

Copy link
Member

commented Feb 22, 2016

This looks like the right approach. Thanks.

sloria added a commit that referenced this pull request Feb 22, 2016

Merge pull request #57 from jmcarp/skip-defined-fields
Skip introspection on defined fields.

@sloria sloria merged commit 961d28b into marshmallow-code:dev Feb 22, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.