Skip to content

Commit 0a2a861

Browse files
committed
server/customer: fix customer update trying to set email to None when explicitly set
1 parent 8818410 commit 0a2a861

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

server/polar/customer/service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def update(
180180
}
181181
)
182182

183-
# Reset verification status
183+
customer.email = customer_update.email
184184
customer.email_verified = False
185185

186186
if (
@@ -220,7 +220,9 @@ async def update(
220220

221221
return await repository.update(
222222
customer,
223-
update_dict=customer_update.model_dump(exclude_unset=True, by_alias=True),
223+
update_dict=customer_update.model_dump(
224+
exclude={"email"}, exclude_unset=True, by_alias=True
225+
),
224226
)
225227

226228
async def delete(self, session: AsyncSession, customer: Customer) -> Customer:

server/tests/customer/test_service.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ async def test_valid_same_external_id(
255255

256256
assert customer.external_id == customer_external_id.external_id
257257

258+
async def test_valid_explicitly_none_email(
259+
self, session: AsyncSession, customer: Customer
260+
) -> None:
261+
updated_customer = await customer_service.update(
262+
session,
263+
customer,
264+
CustomerUpdate(email=None),
265+
)
266+
await session.flush()
267+
268+
assert updated_customer.email == customer.email
269+
258270

259271
@pytest.mark.asyncio
260272
class TestDelete:

0 commit comments

Comments
 (0)