Skip to content

fix(pylibmc): support client initialization using servers [backport 3.2] #12785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2025

Conversation

github-actions[bot]
Copy link
Contributor

Backport e08d99c from #12721 to 3.2.

Currently calling Client(servers=[url]) throws an error as seen with the new test:

Example CI error

FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'
FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'
FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'

This is a bug in our integration logic because you can declare Clients with and without the servers portion: https://sendapatch.se/projects/pylibmc/reference.html .

Why did this bug occur?

When you call pylibmc.Client(servers=[url]), by the time it hits our patch code, **kwargs already stores servers. Then when this gets passed into the Client init, it sees two "servers" https://github.com/lericson/pylibmc/blob/1183e48eb86adf0c23c5164bfe2c2a4058234640/src/pylibmc/client.py#L126, hence the complaint about the multiple server arguments.

A quick fix is to check if the kwargs contains servers and set up the client without duplicating it.

Fixes APMS-15146

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

Currently calling `Client(servers=[url])` throws an error as seen with
the new test:

[Example CI
error](https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-py/-/jobs/847335230)
```
FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'
FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'
FAILED tests/contrib/pylibmc/test.py::TestPylibmcPatch::test_client_with_servers_option - TypeError: __init__() got multiple values for argument 'servers'
```

This is a bug in our integration logic because you can declare Clients
with and without the `servers` portion:
https://sendapatch.se/projects/pylibmc/reference.html .

**Why did this bug occur?**

When you call `pylibmc.Client(servers=[url])`, by the time it hits our
patch code, `**kwargs` already stores `servers`. Then when this gets
passed into the Client init, it sees two "servers"
https://github.com/lericson/pylibmc/blob/1183e48eb86adf0c23c5164bfe2c2a4058234640/src/pylibmc/client.py#L126,
hence the complaint about the multiple server arguments.

A quick fix is to check if the kwargs contains servers and set up the
client without duplicating it.

Fixes APMS-15146

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

---------

Co-authored-by: Brett Langdon <[email protected]>
Co-authored-by: Emmett Butler <[email protected]>
(cherry picked from commit e08d99c)
@wantsui wantsui closed this Mar 18, 2025
@wantsui wantsui reopened this Mar 18, 2025
Copy link
Contributor Author

CODEOWNERS have been resolved as:

releasenotes/notes/pylibmc-bug-fix-client-419c7912f54418b7.yaml         @DataDog/apm-python
ddtrace/contrib/internal/pylibmc/client.py                              @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/pylibmc/test.py                                           @DataDog/apm-core-python @DataDog/apm-idm-python

@wantsui wantsui closed this Mar 18, 2025
@wantsui wantsui reopened this Mar 18, 2025
@pr-commenter
Copy link

pr-commenter bot commented Mar 18, 2025

Benchmarks

Benchmark execution time: 2025-03-28 20:59:30

Comparing candidate commit 2d20629 in PR branch backport-12721-to-3.2 with baseline commit 15f5a7f in branch 3.2.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 430 metrics, 2 unstable metrics.

@wantsui wantsui closed this Mar 18, 2025
@wantsui wantsui reopened this Mar 18, 2025
@wantsui wantsui disabled auto-merge March 28, 2025 23:37
@wantsui wantsui closed this Mar 28, 2025
@wantsui wantsui reopened this Mar 28, 2025
@wantsui wantsui changed the title fix(pylibmc): support client initialization using servers [backport 3.2] fix(pylibmc): support client initialization using servers[backport 3.2] Mar 28, 2025
@wantsui wantsui changed the title fix(pylibmc): support client initialization using servers[backport 3.2] fix(pylibmc): support client initialization using servers [backport 3.2] Mar 28, 2025
@wantsui wantsui enabled auto-merge (squash) March 28, 2025 23:38
@erikayasuda erikayasuda disabled auto-merge March 29, 2025 03:23
@erikayasuda erikayasuda merged commit 3976ec2 into 3.2 Mar 29, 2025
347 checks passed
@erikayasuda erikayasuda deleted the backport-12721-to-3.2 branch March 29, 2025 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants