Git Product home page Git Product logo

marshmallow-pynamodb's People

Contributors

mathewmarcus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

marshmallow-pynamodb's Issues

Using a model subclass results in an empty schema

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

Using attr_name causes the field to be None

Hi.
I'm trying to use the package but I have a lot of fields in python mapped to fields named differently in Dynamo (using the attr_name).
Each of those fields results in a None value when serializing it, and in addition it uses the attr_name instead of the field name.
Example:

class Result(Model):
    app_id = NumberAttribute(attr_name="appId")
    domain = UnicodeAttribute()

class ResultSchema(ModelSchema):
    class Meta:
        model = Result

result = Result(app_id=5, domain='a.com')
ResultSchema().dump(result).data
>>> {'domain': 'a.com', 'appId': None}

Expected:
{'domain': 'a.com', 'app_id': 5}

Changing the model's attributes to the original attribute names is not an option as part of them have symbols that are not supported by python as valid names (appId#version for example)

Thanks

Support for BinaryAttribute

Currently, Binary types are not supported. Any chance of getting these added? I'm willing to submit a PR.

Error construct schema for ListAttribute without `of`

Hi!
There is a problem with ListAttribute():

from pynamodb.models import Model
from marshmallow_pynamodb import ModelSchema


class User(Model):
    nick_names = ListAttribute()


class UserSchema(ModelSchema):
    class Meta:
        model = User
/marshmallow_pynamodb/schema.py", line 39, in get_declared_fields
    element_type = type(attribute.element_type.__name__, (ModelSchema, ), {'Meta': Meta})
AttributeError: 'NoneType' object has no attribute '__name__'

It is understandable that is not so much sense for schema with list without type specification but it is valid model and possible use case.

So it seems two way to handle this issue. First option is forbid create list attribute without specifying type and second is handle this situation and create schema and validate only container type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.