Skip to content

chore(asyncpg): fix flaky test_execute_after_patch_unpatch_patch#18199

Draft
quinna-h wants to merge 1 commit into
mainfrom
dd/fix/flaky-asyncpg-patch-cycle-test
Draft

chore(asyncpg): fix flaky test_execute_after_patch_unpatch_patch#18199
quinna-h wants to merge 1 commit into
mainfrom
dd/fix/flaky-asyncpg-patch-cycle-test

Conversation

@quinna-h
Copy link
Copy Markdown
Contributor

@quinna-h quinna-h commented May 20, 2026

Description

Fixing test_execute_after_patch_unpatch_patch[py3.10]Questions? Ask in #code-gen-flaky-tests

This change stabilizes test_execute_after_patch_unpatch_patch in tests/contrib/asyncpg/test_asyncpg.py.

The flaky failure ('function' object has no attribute '__wrapped__') was categorized as order-dependent and was caused by the test using the patched_conn fixture, which creates the connection before the explicit unpatch()/patch() cycle being validated. That allowed prior test ordering and global asyncpg patch state transitions to influence this test's connection state.

Changes

  • Updated test_execute_after_patch_unpatch_patch to stop using the patched_conn fixture.
  • Created a fresh connection after the unpatch()/patch() cycle inside the test.
  • Added explicit connection cleanup in a try/finally block.

Testing

Risks

Low risk. The change is test-only and narrows scope to per-test local setup/cleanup, improving isolation without changing production behavior.

Additional Notes

None.


PR by Bits - View session in Datadog

Comment @DataDog to request changes

@datadog-official
Copy link
Copy Markdown
Contributor

View session in Datadog

Bits Dev status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown
Contributor

I can only run on private repositories.

@quinna-h quinna-h changed the title Fix flaky test_execute_after_patch_unpatch_patch chore(asyncpg): fix flaky test_execute_after_patch_unpatch_patch May 20, 2026
@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official Bot commented May 20, 2026

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 10 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741589-d2b8243-musllinux_1_2_aarch64, 1]   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). AssertionError: Failed with DD_IAST_ENABLED=0: 1

DataDog/apm-reliability/dd-trace-py | build linux: [arm64, cp315-cp315, v113741589-d2b8243-musllinux_1_2_aarch64]   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). AssertionError: Failed with DD_IAST_ENABLED=0: 1 in native module load test.

Changelog | Validate changelog   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Release note not found during changelog validation

View all 10 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1f1f2b9 | Docs | Datadog PR Page | Give us feedback!

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

Codeowners resolved as

tests/contrib/asyncpg/test_asyncpg.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python

@quinna-h quinna-h added changelog/no-changelog A changelog entry is not required for this PR. ai-generated PR created with AI assistance labels May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated PR created with AI assistance Bits AI changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants