anitabyte / etsyv3

Python client for the Etsy OpenAPI v3
GNU General Public License v3.0
58 stars 24 forks source link

Use nulled variable in Request.get_dict() method instead of self._nullable #5

Closed d-winch closed 1 year ago

d-winch commented 1 year ago

Request.get_dict currently uses the class variable of self._nullable despite creating a local variable nulled from the Request.get_nulled method. This passes all nullable fields to the get_dict method and leaves them missing from the returned dict.

Currently:

req = UpdateListingRequest(materials=["Cotton"], tags=["tag1", "tag2"])
req.get_dict()
{'materials': None, 'tags': None}

With the fix:

req = UpdateListingRequest(materials=["Cotton"], tags=["tag1", "tag2"])
req.get_dict()
{'materials': ['Cotton'], 'tags': ['tag1', 'tag2']}

Currently, the default nullable parameter in util.todict is set to an empty list which is a mutable object. This doesn't currently cause any issues. I have set it to None, then check if it's equal to None before creating it, as mentioned here: https://docs.python.org/3/reference/compound_stmts.html#function-definitions

anitabyte commented 1 year ago

Merged, thank you!