marshmallow-code / marshmallow-code/marshmallow

'NoneType' object is not subscriptable when serializing fields that do not belong to the database is None

Open
#2,833 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

```py
class UserConfig(SQLModel, table=True):
__tablename__ = "user_config"
id: Optional[int] = Field(default=None, primary_key=True)
user_id: Optional[int]
_user_name: str = '' #---> not in database fields

@property
def user_name(self):
return self._user_name

@user_name.setter
def user_name(self, user_name):
self._user_name = user_name

class UserConfigSchema(Schema):
user_id = fields.Int()
user_name = fields.Str(allow_none= True)
id = fields.Int()

class Meta:
model = UserConfig
unknown = EXCLUDE
```

user_config_schema.dumps(user_config) # --->issue NoneType .....
what i should to do in that time.
Please confirm whether it needs to be repaired or if there are any solutions other than @post_dump

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 failure with the shown UserConfig, UserConfigSchema, and user_config_schema.dumps(user_config) example. Trace how the schema resolves the user_name property when serializing a field absent from the database, then establish whether the desired outcome is successful serialization or documented use of a workaround and verify it with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.