marshmallow-code / marshmallow-code/marshmallow
v3 no longer accepts fields that call class methods
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
While upgrading from v2.21.0 to v3.10.0, I have found a difference in behaviour that I could not find in the Changelog / update docs.
I have created a contrived case to show the issue:
```
import marshmallow
class Test(marshmallow.Schema):
number = marshmallow.fields.Number()
class TestObject(object):
def number(self):
return 1
if marshmallow.__version__.startswith("3"):
print(Test().dump(TestObject()))
else:
print(Test().dump(TestObject()).data)
```
When run in `marshmallow==2.21.0`, the output is:
```
{'number': 1.0}
```
while when run in `marshmallow==3.10.0`, I get this error:
```
TypeError: float() argument must be a string or a number, not 'method'
```
Can anybody shed some light on this difference in behaviour? Is it to be expected or is it a bug?
If it is expected, what is the best way to deal with this for the upgrade?
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 running the supplied marshmallow Schema and TestObject reproduction against versions 2.21.0 and 3.10.0, then trace the dump behavior for the field whose value is a class method. Done means the version difference is explained and the issue has either documented upgrade guidance or a confirmed regression with a focused regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100