````text FAILED tests/test_refund.py::test_refund_with_none_guard - AssertionError: assert None is not None FAILED tests/test_payment.py::test_process_payment_with_refunds - IndexError: list index out of range FAILED tests/test_validation.py::test_validate_order_items - AttributeError: 'NoneType' object has no attribute 'items' =================================== FAILURES =================================== ______________________________ test_refund_with_none_guard ______________________________ def test_refund_with_none_guard(self): refund = RefundService.create_partial_refund(order_id=123, line_items=None) > assert refund.events is not None E AssertionError: assert None is not None E + where None = RefundResult(success=False, events=None, error='NoneType object is not iterable').events tests/test_refund.py:45: AssertionError ----------------------------- Captured stdout call ----------------------------- 2025-08-29 10:15:23,456 DEBUG [RefundService] Starting refund processing for order 123 2025-08-29 10:15:23,457 INFO [Database] Connecting to postgres://prod-db:5432/payments 2025-08-29 10:15:23,459 DEBUG [RefundService] Processing line_items: None 2025-08-29 10:15:23,459 DEBUG [RefundService] Validating refund parameters... 2025-08-29 10:15:23,460 DEBUG [RefundService] Iterating through line_items... Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute cursor.execute(statement, parameters) psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type uuid: "None" During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/payments/refund.py", line 118, in process_line_items for item in line_items: TypeError: 'NoneType' object is not iterable 2025-08-29 10:15:23,461 ERROR [RefundService] Refund failed due to invalid line_items 2025-08-29 10:15:23,462 INFO [Database] Connection closed ________________________ test_process_payment_with_refunds ________________________ def test_process_payment_with_refunds(self): payment = Payment.objects.create(amount=100.00, status='completed') refunds = payment.get_refunds() > assert refunds[0].amount == 25.00 E IndexError: list index out of range tests/test_payment.py:78: IndexError ----------------------------- Captured stderr call ----------------------------- django.db.utils.IntegrityError: FOREIGN KEY constraint failed git log --oneline -10 payments/refund.py a1b2c3d Remove redundant None checks in refund processing 854cc73 Add validation for refund amounts b764ad9 Fix refund event creation timing 89f0ac7 Update refund processing to handle edge cases 853ea43 Optimize database queries in refund flow ... git blame payments/refund.py | grep -A5 -B5 "for item in line_items" 115: @staticmethod 116: def process_line_items(line_items): 117: a1b2c3d (dev-team 2025-08-28 14:23:15 -0700) + # Upstream should validate line_items 118: a1b2c3d (dev-team 2025-08-28 14:23:15 -0700) + 119: 9a7f614 (alice 2025-08-15 09:45:32 -0700) processed = [] 120: a1b2c3d (dev-team 2025-08-28 14:23:15 -0700) + for item in line_items: ... commit a1b2c3d4e5f6789 (HEAD -> feature/refund-fix, origin/feature/refund-fix) Author: dev-team <[email protected]> Date: Wed Aug 28 14:23:15 2025 -0700 Remove redundant None checks in refund processing - Cleaned up defensive programming patterns - Simplified line_items processing logic - Assumes upstream validation handles None cases - Part of tech debt cleanup initiative payments/refund.py | 3 +-- tests/test_refund.py | 2 +- docs/refund_api.md | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/payments/refund.py b/payments/refund.py index 1234567..abcdefg 100644 --- a/payments/refund.py +++ b/payments/refund.py @@ -115,8 +115,7 @@ class RefundService: @staticmethod def process_line_items(line_items): - if line_items is None: - return [] + # Upstream should validate line_items processed = [] for item in line_items: stdout from application logs: 2025-08-29 10:15:20.123 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) 2025-08-29 10:15:20.127 [main] INFO com.company.PaymentsApplication - Started PaymentsApplication in 2.456 seconds 2025-08-29 10:15:23.445 [http-nio-8080-exec-1] INFO c.c.p.controller.RefundController - POST /api/refunds 2025-08-29 10:15:23.446 [http-nio-8080-exec-1] DEBUG c.c.p.service.RefundService - Processing refund request: {"order_id": 123, "line_items": null} 2025-08-29 10:15:23.447 [http-nio-8080-exec-1] WARN c.c.p.service.ValidationService - Received null line_items, proceeding anyway 2025-08-29 10:15:23.461 [http-nio-8080-exec-1] ERROR c.c.p.service.RefundService - NoneType iteration error in process_line_items 2025-08-29 10:15:23.462 [http-nio-8080-exec-1] ERROR c.c.p.controller.RefundController - HTTP 500: Internal server error during refund processing ```