Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Merged
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants