From 95a0e9c0f18d254b35ab46ee06e7c3b2caa9ee14 Mon Sep 17 00:00:00 2001 From: James Kachel Date: Thu, 27 Feb 2025 14:40:24 -0600 Subject: [PATCH] Wraps the CyberSource imports in a warnings filter, so we get less chatter from SyntaxWarning issues The CyberSource Python REST client library uses a couple of regexes that aren't in raw strings, and (starting with Python 3.12) doing that raises a SyntaxWarning. (This was deprecated in 3.6 but in between then and 3.12 it raised a DeprecationWarning, which is usually invisible.) Wrapping these in a `catch_warnings` context manager lets us filter out SyntaxWarning, so we can make it quiet. (pytest also sometimes regards these as _errors_, which keeps your tests from passing when using Python 3.12+, so this should fix that too.) It would be better for the upstream to be fixed but we can do this until that happens. --- ...142343_jkachel_wrap_cybersource_imports.md | 40 +++++++++++++++++++ .../mitol/payment_gateway/api.py | 23 ++++++----- uv.lock | 4 +- 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 src/payment_gateway/changelog.d/20250227_142343_jkachel_wrap_cybersource_imports.md diff --git a/src/payment_gateway/changelog.d/20250227_142343_jkachel_wrap_cybersource_imports.md b/src/payment_gateway/changelog.d/20250227_142343_jkachel_wrap_cybersource_imports.md new file mode 100644 index 00000000..72fdf62e --- /dev/null +++ b/src/payment_gateway/changelog.d/20250227_142343_jkachel_wrap_cybersource_imports.md @@ -0,0 +1,40 @@ + + + + +### Changed + +- Wrap the imports for CyberSource; they generate `SyntaxWarning`s, so this should quiet them down (and allow them to pass tests) + + + + diff --git a/src/payment_gateway/mitol/payment_gateway/api.py b/src/payment_gateway/mitol/payment_gateway/api.py index acdfd7f0..f1b063fc 100644 --- a/src/payment_gateway/mitol/payment_gateway/api.py +++ b/src/payment_gateway/mitol/payment_gateway/api.py @@ -7,21 +7,24 @@ import hmac import json import uuid +import warnings from base64 import b64encode from dataclasses import dataclass from decimal import Decimal from functools import wraps -from CyberSource import ( - CreateSearchRequest, - Ptsv2paymentsClientReferenceInformation, - Ptsv2paymentsidcapturesOrderInformationAmountDetails, - Ptsv2paymentsidrefundsOrderInformation, - RefundApi, - RefundPaymentRequest, - SearchTransactionsApi, - TransactionDetailsApi, -) +with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=SyntaxWarning) + from CyberSource import ( + CreateSearchRequest, + Ptsv2paymentsClientReferenceInformation, + Ptsv2paymentsidcapturesOrderInformationAmountDetails, + Ptsv2paymentsidrefundsOrderInformation, + RefundApi, + RefundPaymentRequest, + SearchTransactionsApi, + TransactionDetailsApi, + ) from django.conf import settings from mitol.common.utils.datetime import now_in_utc diff --git a/uv.lock b/uv.lock index 9887b33f..999b6ab7 100644 --- a/uv.lock +++ b/uv.lock @@ -1268,7 +1268,7 @@ requires-dist = [ [[package]] name = "mitol-django-google-sheets" -version = "2025.2.4" +version = "2025.2.27" source = { editable = "src/google_sheets" } dependencies = [ { name = "django" }, @@ -1318,7 +1318,7 @@ requires-dist = [ [[package]] name = "mitol-django-google-sheets-refunds" -version = "2025.2.3" +version = "2025.2.27" source = { editable = "src/google_sheets_refunds" } dependencies = [ { name = "django" },