Hisernberg opened a new pull request, #2216:
URL: https://github.com/apache/libcloud/pull/2216
## Description
`BuddyNSResponse`, `DNSPodResponse`, `LuadnsResponse` and `NsOneResponse`
declare `errors`/`objects` as **class-level mutable attributes** and append to
them from `parse_body_and_errors()`. The lists are therefore shared by every
response object in the process:
- parsed objects **accumulate across requests**:
`libcloud/dns/drivers/nsone.py` `get_zone()` reads `response.objects[0]` and
can receive data from an earlier response;
- errors leak between requests, so `success()` can report stale failures.
Reproduced locally against `trunk`:
```python
from types import SimpleNamespace
from libcloud.common.buddyns import BuddyNSResponse
def raw(body):
return SimpleNamespace(headers={}, body=body, text=body, status_code=200,
reason="OK", request=None, iter_content=lambda
*a: iter([]))
r1 = BuddyNSResponse(response=raw('{"zones": [1]}'), connection=None)
r2 = BuddyNSResponse(response=raw('{"zones": [2]}'), connection=None)
print(r2.objects) # [{'zones': [1]}, {'zones': [2]}] <- stale first
response inside r2
```
## Fix
Initialize fresh per-instance `errors`/`objects` lists **before**
`super().__init__()` (the base `Response` constructor calls `success()`, which
reads `errors`), and convert the class attributes to bare annotations.
Per-request behavior is otherwise unchanged.
## Tests
Regression tests added to all four driver test suites
(`libcloud/test/dns/test_buddyns.py`, `test_dnspod.py`, `test_luadns.py`,
`test_nsone.py`):
- `test_objects_do_not_accumulate_across_responses`
- `test_errors_do_not_leak_across_responses`
With the old code the four suites report **4 failures + 1 error**; with this
change all **60 tests pass**.
## AI Generation Disclosure
Developed with AI assistance (agent workflow): the bug was found by an AST
scan for mutated class-level attributes, reproduced against trunk, fixed, and
verified with the A/B test run above.
@CameronGillespie @anthonytw — apologies, no need to review; tagging no one.
(placeholder-free note: no maintainer tags intended)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]