From 30c150a0a4cd5f53bc7cde3f8c4d5f650996fe55 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Sat, 28 Jul 2018 10:38:44 +0300 Subject: [PATCH] Always save CharFields and TextFields as empty strings instead of nulls Fixes #713 Touches #468 --- djstripe/models/base.py | 10 ++++++++-- tests/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/djstripe/models/base.py b/djstripe/models/base.py index f9d4239160..065c3abd10 100644 --- a/djstripe/models/base.py +++ b/djstripe/models/base.py @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index 3ab978aaf6..24324fa529 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1171,8 +1171,8 @@ def pay(self): "email": "djstripe@example.com", "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",