mathewmarcus / marshmallow-pynamodb Goto Github PK
View Code? Open in Web Editor NEWPynamoDB integration with marshmallow
License: MIT License
PynamoDB integration with marshmallow
License: MIT License
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
could you please add support for this field type
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
I updated the packages of my project and had problems with the use of this plugin.
I think it's related to the Breaking changes in the major relase 4.0 of pynamodb I installed.
To be honest I am not 100% sure it was this project but I think the changes to pynamodb could cause problems here
Currently, Binary types are not supported. Any chance of getting these added? I'm willing to submit a PR.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.