Skip to content

Commit a6ffe7a

Browse files
Merge upstream and update generated code for v2149 and
2 parents 1bb70fa + 96545ff commit a6ffe7a

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-4
lines changed

API_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0822236fb875490aa7ccc7b66dbb52f8965ee062
1+
499f00588b1b41670a44a1e00598db81222ce169

OPENAPI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2148
1+
v2149

stripe/_encode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def _api_encode(data) -> Generator[Tuple[str, Any], None, None]:
3131
for key, value in data.items():
3232
if value is None:
3333
continue
34-
elif hasattr(value, "stripe_id"):
35-
yield (key, value.stripe_id)
34+
elif hasattr(value, "id"):
35+
yield (key, getattr(value, "id"))
3636
elif isinstance(value, list) or isinstance(value, tuple):
3737
for i, sv in enumerate(value):
3838
# Always use indexed format for arrays

stripe/_plan.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class TransformUsage(StripeObject):
9999
"""
100100
Always true for a deleted object
101101
"""
102+
external_reference: Optional[str]
103+
"""
104+
A custom identifier for this price, such as a SKU number or product code, that can be used to reference records from external systems.
105+
"""
102106
id: str
103107
"""
104108
Unique identifier for the object.

stripe/_price.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ class TransformQuantity(StripeObject):
220220
"""
221221
Always true for a deleted object
222222
"""
223+
external_reference: Optional[str]
224+
"""
225+
A custom identifier for this price, such as a SKU number or product code, that can be used to reference records from external systems.
226+
"""
223227
id: str
224228
"""
225229
Unique identifier for the object.

tests/test_encode.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import warnings
2+
3+
from stripe._stripe_object import StripeObject
4+
from stripe._encode import _api_encode
5+
6+
7+
class TestApiEncode:
8+
def test_encode_stripe_object_without_id_no_deprecation_warning(self):
9+
"""
10+
Test that encoding a StripeObject without an id (like metadata)
11+
does not trigger a deprecation warning.
12+
Regression test for issue #1651.
13+
"""
14+
metadata = StripeObject()
15+
metadata["key1"] = "value1"
16+
metadata["key2"] = "value2"
17+
18+
with warnings.catch_warnings(record=True) as w:
19+
warnings.simplefilter("always")
20+
result = list(_api_encode({"metadata": metadata}))
21+
22+
# Check no deprecation warnings were raised
23+
deprecation_warnings = [
24+
warning
25+
for warning in w
26+
if issubclass(warning.category, DeprecationWarning)
27+
]
28+
assert len(deprecation_warnings) == 0, (
29+
f"Expected no deprecation warnings, but got {len(deprecation_warnings)}"
30+
)
31+
32+
# Verify the metadata was encoded correctly as nested dict
33+
assert result == [
34+
("metadata[key1]", "value1"),
35+
("metadata[key2]", "value2"),
36+
]
37+
38+
def test_encode_stripe_object_with_id_extracts_id(self):
39+
"""
40+
Test that encoding a StripeObject with an id (like a customer reference)
41+
correctly extracts just the id value.
42+
"""
43+
customer = StripeObject()
44+
customer["id"] = "cus_123"
45+
customer["name"] = "Test Customer"
46+
47+
with warnings.catch_warnings(record=True) as w:
48+
warnings.simplefilter("always")
49+
result = list(_api_encode({"customer": customer}))
50+
51+
# Check no deprecation warnings were raised
52+
deprecation_warnings = [
53+
warning
54+
for warning in w
55+
if issubclass(warning.category, DeprecationWarning)
56+
]
57+
assert len(deprecation_warnings) == 0, (
58+
f"Expected no deprecation warnings, but got {len(deprecation_warnings)}"
59+
)
60+
61+
# Should encode to just the ID
62+
assert result == [("customer", "cus_123")]
63+
64+
def test_encode_regular_dict(self):
65+
"""Test that regular dicts are encoded as nested dicts."""
66+
regular_dict = {"key1": "value1", "key2": "value2"}
67+
result = list(_api_encode({"data": regular_dict}))
68+
69+
assert result == [
70+
("data[key1]", "value1"),
71+
("data[key2]", "value2"),
72+
]
73+
74+
def test_encode_none_value_skipped(self):
75+
"""Test that None values are skipped during encoding."""
76+
result = list(_api_encode({"field": None}))
77+
assert result == []
78+
79+
def test_encode_string_value(self):
80+
"""Test that string values are encoded directly."""
81+
result = list(_api_encode({"name": "John Doe"}))
82+
assert result == [("name", "John Doe")]
83+
84+
def test_encode_boolean_value(self):
85+
"""Test that boolean values are encoded as lowercase strings."""
86+
result = list(_api_encode({"active": True, "deleted": False}))
87+
assert result == [("active", "true"), ("deleted", "false")]
88+
89+
def test_encode_list_value(self):
90+
"""Test that list values are encoded with indexed keys."""
91+
result = list(_api_encode({"items": ["item1", "item2", "item3"]}))
92+
assert result == [
93+
("items[0]", "item1"),
94+
("items[1]", "item2"),
95+
("items[2]", "item3"),
96+
]

0 commit comments

Comments
 (0)