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

missing getting used on read? #112

Open
philiplb opened this issue Aug 4, 2023 · 0 comments
Open

missing getting used on read? #112

philiplb opened this issue Aug 4, 2023 · 0 comments

Comments

@philiplb
Copy link

philiplb commented Aug 4, 2023

Hi,

it seems that the missing parameter gets used on reading despite the documentation stating this:

NOTE: Marshmallow uses the missing keyword during deserialization, which occurs when we save

Or do I use it the wrong way? I want to test some behaviour of our application in cases where a new field was added to a model about how old entries behave.

First, I define the old structure and add the table:

class ReducedTestModel(DynaModel):
    class Table:
        name = "test-model"
        hash_key = "name"
        read = 25
        write = 5
        if dynamoDBHost():
            resource_kwargs = {"endpoint_url": dynamoDBHost()}

    class Schema:
        name = fields.String()
        foo = fields.String(missing=lambda: "afoo")

ReducedTestModel.Table.create_table()

Then an entry gets stored:

reducedEntity = ReducedTestModel()
reducedEntity.name = "theOldOne"
reducedEntity.save()

Now, I define a new model being the same as the old one except one added field:

class FullTestModel(DynaModel):
    class Table:
        name = "test-model"
        hash_key = "name"
        read = 25
        write = 5
        if dynamoDBHost():
            resource_kwargs = {"endpoint_url": dynamoDBHost()}

    class Schema:
        name = fields.String()
        foo = fields.String(missing=lambda: "afoo")
        bar = fields.String(missing=lambda: "abar")

Read the stored "old" entity from the new model and print the new attribute:

fullEntity = FullTestModel.get(name=reducedEntity.name)
print(fullEntity.bar)

The output is "abar", so it used the missing attribute. But why? Expectation was actually a crash due to a missing attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant