marshmallow-code / marshmallow-code/marshmallow
'NoneType' object is not subscriptable when serializing fields that do not belong to the database is None
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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