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

Using a model subclass results in an empty schema #3

Open
bugeats opened this issue Jan 22, 2019 · 0 comments
Open

Using a model subclass results in an empty schema #3

bugeats opened this issue Jan 22, 2019 · 0 comments

Comments

@bugeats
Copy link

bugeats commented Jan 22, 2019

It appears that the ModelSchema is somehow unable to introspect the attributes of a model if it is a subclass of another model. Subclassing in this manner works fine in pynamodb, and it is expected that it would work here as well.

Test case:

from pynamodb.attributes import UnicodeAttribute
from pynamodb.models import Model
from marshmallow_pynamodb import ModelSchema


class Base(Model):
    class Meta:
        table_name = 'test-table'
    pk = UnicodeAttribute(hash_key=True)
    alpha = UnicodeAttribute(null=True)


class Sub(Base):
    class Meta(Base.Meta):
        pass


class BaseSchema(ModelSchema):
    class Meta:
        model = Base


class SubSchema(ModelSchema):
    class Meta:
        model = Sub


sub_schema = SubSchema()
base_schema = BaseSchema()

base_dumped = base_schema.dump(Base(pk='peekay', alpha='hi mom')).data
assert base_dumped['alpha'] == 'hi mom' # <-- PASSES OK

sub_dumped = sub_schema.dump(Sub(pk='peekay', alpha='hi mom')).data
assert sub_dumped['alpha'] == 'hi mom' # <-- FAILS
@bugeats bugeats changed the title Uses a model subclass results in an empty schema Using a model subclass results in an empty schema Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants