Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always save CharFields and TextFields as empty strings instead of nulls
Browse files Browse the repository at this point in the history
jleclanche committed Jul 28, 2018
1 parent 0ee3239 commit 30c150a
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions djstripe/models/base.py
Original file line number Diff line number Diff line change
@@ -176,10 +176,16 @@ def _stripe_object_to_record(cls, data):
# TODO (#681): Handle foreign keys automatically
# For now they're handled in hooks.
continue

if hasattr(field, "stripe_to_db"):
result[field.name] = field.stripe_to_db(manipulated_data)
field_data = field.stripe_to_db(manipulated_data)
else:
result[field.name] = manipulated_data.get(field.name)
field_data = manipulated_data.get(field.name)

if isinstance(field, (models.CharField, models.TextField)) and field_data is None:
field_data = ""

result[field.name] = field_data

return result

4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1171,8 +1171,8 @@ def pay(self):
"email": "[email protected]",
"payouts_enabled": True,
"statement_descriptor": "DJSTRIPE",
"support_email": "djstripe@exmaple.com",
"support_phone": "",
"support_email": "djstripe@example.com",
"support_phone": None,
"support_url": "https://example.com/support/",
"timezone": "Etc/UTC",
"type": "standard",

0 comments on commit 30c150a

Please sign in to comment.