-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Running py 3.8 on win10, 32-bit. Using desert 7ca1e23 from git.
When making a schema from data class A, calling schema.dump(a) to serialize an object a, will fail the serialization if class A contains a method named dump.
def test_calling_dump():
@attr.s
class A:
x: int = attr.ib(default=0)
def dump(self, *args, **kw):
raise Exception(f"A.dump({args},{kw}) should not be called")
schema = desert.schema(A)
a = A()
schema.dump(a)If it happens that the defintion of A.dump() is incompatible with schema.dump(), a very strange error is returned that is confusing at best:
File "c:\sveinse\myfile\settings.py", line 153, in dumps
load = schema.dump(self)
TypeError: dump() takes 1 positional argument but 2 were given
The calling of methods in the data class from the schema object can be extended to any arbitrary function names, e.g. foof as shown below. Note that if schema.foof(a) is called, then A.foof will be called with arguments foof(schema_object, self), not adhering to the defined prototype def foof(self,...). This can lead to very unexpected results.
def test_calling_foof():
@attr.s
class A:
x: int = attr.ib(default=0)
def foof(self, *args, **kw):
raise Exception(f"A.foof({type(self)},{args},{kw}) should not be called")
schema = desert.schema(A)
a = A()
schema.foof(a)Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working