Jump to solution
Verify

The Fix

pip install stripe==14.4.0a2

Based on closed stripe/stripe-python issue #259 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -1,6 +1,7 @@ import warnings import sys +from copy import deepcopy from stripe import api_requestor, error, util, upload_api_base
repro.py
Error Traceback (most recent call last): File "/home/user/Projects/env27/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/home/user/Projects/tests.py", line 759, in test_charge_api_response_body_parsing_errors deepcopy(event) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct state = deepcopy(state, memo) File "/usr/lib/python2.7/copy.py", line 163, in deepcopy y = copier(x, memo) File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 358, in _reconstruct y[key] = value File "/home/user/Projects/env27/local/lib/python2.7/site-packages/stripe/resource.py", line 110, in __setitem__ k, str(self), k)) ValueError: You cannot set address_zip to an empty string. We interpret empty strings as None in requests.You may set { "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip_check": null, "brand": "Visa", "cvc_check": "pass", "dynamic_last4": null, "exp_month": 11, "exp_year": 2015, "fingerprint": "****************", "funding": "credit", "id": "card_************************", "last4": "4242", "metadata": {}, "object": "card", "tokenization_method": null }.address_zip = None to delete the property
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install stripe==14.4.0a2\nWhen NOT to use: This fix should not be used if empty string values are expected to be valid.\n\nOption C — Workaround\n`event_dict = json.loads(str(event))`. This will return a `dict` with all nested `StripeObject`s cast as `dict` themselves.\nWhen NOT to use: This fix should not be used if empty string values are expected to be valid.\n\n

Why This Fix Works in Production

  • Trigger: Error
  • Mechanism: Deepcopy fails on StripeObject when empty string values are present due to overridden setters
  • Why the fix works: Implemented copy and deepcopy overrides on StripeObject to prevent exceptions when copying objects with empty string values. (first fixed release: 14.4.0a2).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 2.7 in real deployments (not just unit tests).
  • Deepcopy fails on StripeObject when empty string values are present due to overridden setters
  • Surfaces as: Error

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Interesting. I think what's happening here is that deepcopy casts event to a dict, but the nested object in the data key is still a…”
@olivierbellone · 2016-10-25 · source
“Terrible workaround: event_dict = json.loads(str(event)). This will return a dict with all nested StripeObjects cast as dict themselves.”
@olivierbellone · 2016-10-25 · source
“> Interesting”
@brandur · 2016-10-25 · source

Failure Signature (Search String)

  • Error

Error Message

Stack trace
error.txt
Error Message ------------- Error Traceback (most recent call last): File "/home/user/Projects/env27/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/home/user/Projects/tests.py", line 759, in test_charge_api_response_body_parsing_errors deepcopy(event) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct state = deepcopy(state, memo) File "/usr/lib/python2.7/copy.py", line 163, in deepcopy y = copier(x, memo) File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py" ... (truncated) ...

Minimal Reproduction

repro.py
Error Traceback (most recent call last): File "/home/user/Projects/env27/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/home/user/Projects/tests.py", line 759, in test_charge_api_response_body_parsing_errors deepcopy(event) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 334, in _reconstruct state = deepcopy(state, memo) File "/usr/lib/python2.7/copy.py", line 163, in deepcopy y = copier(x, memo) File "/usr/lib/python2.7/copy.py", line 257, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 357, in _reconstruct value = deepcopy(value, memo) File "/usr/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/usr/lib/python2.7/copy.py", line 358, in _reconstruct y[key] = value File "/home/user/Projects/env27/local/lib/python2.7/site-packages/stripe/resource.py", line 110, in __setitem__ k, str(self), k)) ValueError: You cannot set address_zip to an empty string. We interpret empty strings as None in requests.You may set { "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip_check": null, "brand": "Visa", "cvc_check": "pass", "dynamic_last4": null, "exp_month": 11, "exp_year": 2015, "fingerprint": "****************", "funding": "credit", "id": "card_************************", "last4": "4242", "metadata": {}, "object": "card", "tokenization_method": null }.address_zip = None to delete the property

Environment

  • Python: 2.7

What Broke

Attempting to deepcopy an event object raises an exception, causing application errors.

Why It Broke

Deepcopy fails on StripeObject when empty string values are present due to overridden setters

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install stripe==14.4.0a2

When NOT to use: This fix should not be used if empty string values are expected to be valid.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

`event_dict = json.loads(str(event))`. This will return a `dict` with all nested `StripeObject`s cast as `dict` themselves.

When NOT to use: This fix should not be used if empty string values are expected to be valid.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/stripe/stripe-python/pull/260

First fixed release: 14.4.0a2

Last verified: 2026-02-08. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if empty string values are expected to be valid.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
14.4.0a2 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.