Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

missing getting used on read? #112

Description

@philiplb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions