Skip to content

v3 no longer accepts fields that call class methods  #1758

Open
@acelletti

Description

@acelletti

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions