Skip to content

fix(core): multiple container start invocations with custom labels #769

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 1 commit into from
Feb 11, 2025
Merged

fix(core): multiple container start invocations with custom labels #769

merged 1 commit into from
Feb 11, 2025

Conversation

neykov
Copy link
Contributor

@neykov neykov commented Feb 11, 2025

When invoking .start() multiple times on the same DockerContainer instance, the call fails with ValueError: The org.testcontainers namespace is reserved for internal use error.

Example code:

from testcontainers.core.container import DockerContainer
container = DockerContainer("alpine:latest").with_kwargs(labels={})
container.start()
container.stop()
container.start()

The fix is to update labels for the container in a copy of the user-provided dictionary, so that:

  • the code doesn't mutate user structures
  • avoid side effects, allowing for multiple .start() invocations

When invoking .start() multiple times on the same DockerContainer instance,
the call fails with "ValueError: The org.testcontainers namespace is reserved for internal use" error.

Example code:

```
from testcontainers.core.container import DockerContainer
container = DockerContainer("alpine:latest").with_kwargs(labels={})
container.start()
container.stop()
container.start()
```

The fix is to update labels for the container in a copy of the user-provided dictionary,
so that:
* the code doesn't mutate user structures
* avoid side effects, allowing for multiple .start() invocations
@alexanderankin alexanderankin changed the title Fix for multiple container start invocations with custom labels fix: multiple container start invocations with custom labels Feb 11, 2025
@alexanderankin alexanderankin changed the title fix: multiple container start invocations with custom labels fix(core): multiple container start invocations with custom labels Feb 11, 2025
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@9317736). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #769   +/-   ##
=======================================
  Coverage        ?   85.32%           
=======================================
  Files           ?       12           
  Lines           ?      668           
  Branches        ?      105           
=======================================
  Hits            ?      570           
  Misses          ?       75           
  Partials        ?       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexanderankin alexanderankin merged commit 3e783a8 into testcontainers:main Feb 11, 2025
11 of 12 checks passed
@neykov neykov deleted the no-labels-reuse branch February 12, 2025 12:05
alexanderankin pushed a commit that referenced this pull request Mar 5, 2025
🤖 I have created a release *beep* *boop*
---


##
[4.9.2](testcontainers-v4.9.1...testcontainers-v4.9.2)
(2025-02-26)


### Bug Fixes

* Change env var disabling OpenSearch security plugin
([#773](#773))
([2620d7f](2620d7f))
* **core:** create_label test
([#771](#771))
([7517297](7517297))
* **core:** multiple container start invocations with custom labels
([#769](#769))
([3e783a8](3e783a8))
* **keycloak:** Fixed Keycloak testcontainer for latest version v26.1.0
([#766](#766))
([b1642e9](b1642e9))
* **scylla:** scylla get cluster method
([#778](#778))
([46913c1](46913c1))


### Documentation

* Fixed typo in CONTRIBUTING.md
([#767](#767))
([f0bb0f5](f0bb0f5))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants