marshmallow-code / marshmallow-code/marshmallow-sqlalchemy

I suspect a breaking change related to "include_relationships=True" and schema.load() in version 1.4.1

Open
#664 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Python
Stars
580
Forks
101
Avg merge
7h 6m
Merged PRs (30d)
3

Description

Hi ! I recently had to do some testing on my local for some portion of our code that's been running happily on staging. I didn't specify a version number for my local container instance, as such it pulled 1.4.1 which is the latest. I noticed that it seems to enforce implicitly defined fields (from the include_relationships=True option), during a schema.load() which I THINK isn't the desired or USUAL behavior.

Typically (in previous versions specifically 1.1.0 ) we've been able to deserialize into objects with schemas defined with the include_relationships option set to True - without having to provide values for relationship fields (which intuitively makes sense), however for some reason it's raising a Validation (Missing field) error on 1.4.1 . This behavior wasn't reproducable on 1.1.0 (not that I would know if this is on later versions in: 1.1.0 < version < 1.4.1 because we've not used any other up until my recent local testing which used 1.4.1).

class UserSchema(Base):
    class Meta:
        model = User
        include_relationships=True  # includes for example an 'address' relationship attr (could be something like a 'backref' or explicitly declared field on the sqlalchemy model)
        include_fk = True
        load_instance = True

# usage and expected behavior
schema = UserSchema(unknown='exclude', session=session)
user = schema.load(**data)
# returns <User> object

# Observed behavior
# .. same steps
# throws 'Missing data for required 'address' field - error'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the UserSchema example with marshmallow-sqlalchemy 1.4.1 and compare it with 1.1.0, focusing on schema.load() when include_relationships=True and relationship data is absent. Trace where the relationship field becomes required; done means relationship fields can again be omitted during loading without a missing-field validation error, while the reported behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.