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

Raise error when ModelSerializer used with abstract model #2757

Conversation

ekiourk
Copy link
Contributor

@ekiourk ekiourk commented Mar 23, 2015

Closes #2630

Raising an exception (ValueError) if an abstract model is used with a ModelSerializer. The check is happening in get_fields method of the ModelSerializer immediately after some other similar checks.

Do you think is better to make the checks earlier? Maybe in the constructor?

"""
Given a model class, returns a boolean True if it is abstract and False if it is not.
"""
return hasattr(model, 'Meta') and hasattr(model._meta, 'abstract') and model._meta.abstract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking hasattr(model, '_meta') (not 'Meta').

tomchristie added a commit that referenced this pull request Apr 27, 2015
…Serializer-used-with-abstract-model

Raise error when ModelSerializer used with abstract model
@tomchristie tomchristie merged commit 2394577 into encode:master Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise error when ModelSerializer used with abstract model.
3 participants