Skip to content

Conversation

@neykov
Copy link
Contributor

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
@alexanderankinalexanderankin changed the title Fix for multiple container start invocations with custom labelsfix: multiple container start invocations with custom labelsFeb 11, 2025
@alexanderankinalexanderankin changed the title fix: multiple container start invocations with custom labelsfix(core): multiple container start invocations with custom labelsFeb 11, 2025
@codecov
Copy link

codecovbot 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.

@alexanderankinalexanderankin merged commit 3e783a8 into testcontainers:mainFeb 11, 2025
11 of 12 checks passed
@neykovneykov deleted the no-labels-reuse branch February 12, 2025 12:05
@neykovneykov mentioned this pull request Feb 24, 2025
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 freeto 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

@neykov@alexanderankin