-
Notifications
You must be signed in to change notification settings - Fork 297
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
fix(postgres): Remove SqlAlchemy dependency from postgres container #445
fix(postgres): Remove SqlAlchemy dependency from postgres container #445
Conversation
Based on #340 by @logicbomb, I only rebased it and removed the dependency from pyproject-toml. Original PR description by @logicbomb:
One outstanding review comment by @totallyzen:
So what's the alternative (in the order of my preference, best to lowest)?
I didn't apply any changes in any of these directions yet, the current PR is just a rebase and small fix for the dependencies and newer PG versions in tests and examples. |
0132a27
to
56f8081
Compare
|
Hm... I'm open to suggestions! 🤔 Let me think out aloud... How I view the value of these containers... focus on
I think I'd like both of the first 2 options:
I am however happy if you only implement just one of those. I think you see where I'm coming from! WDYT? |
Does that module life under (I haven't understood why this split is needed, poetry build seems to "undo" it with all the includes, the only reason I can think of is that it made splitting the packages was easier but that's seems to be not needed anymore? for having the test "nearer" to the specific code?) Another question_ do you consider these classes API or implementation detail? E.g. if I rename |
Ok, one additional idea for the refactoring would be to just extract the sqla based So the DBContainer would be: from abc import ABC, abstractmethod
class DBContainer(ABC):
@abstractmethod
def _connect(self):
"""Check if the container is ready."""
@abstractmethod
def _configure(self):
"""Does basic setup so the container can start up (User, passwort, etc)."""
@abstractmethod
def get_connection_url(self, *, **kwargs): # psycopg v3 cannot handle sqla style URLs, so it needs a driver=None :-(
"""Get a DB connection URL which can be used to connect to the DB."""
def _create_connection_url( ... as now ...):
"""Helper to create a DB API connection URL.""" (although he first two could actually be part of the DockerContainer interface... Most containers have that method already and the rest does that stuff in Overall this is a BIG refactoring and it will touch probably half of the modules... |
I'm willing to hear "chill dude, it's fine". Please do call me out on my bias/pedanticism! I'm not averse to negative feedback. 🙂 The API level problem is what you are saying with
In terms of dev experience, I think you are onto something! It would cause the least amount of hassle and focus on meaningful fixes rather than my personal pedantic issues with Final note on breaking changes -> we have semver for this exact reason! I tried to condense my thoughts, I hope this helps! |
To simplify your life for right now:
Aye, we can take it in two steps:
As for 5.x, we already have another important change that might break the API in the face of #314 which would put a time limit on container life (though I'm thinking how to implement this without breaking the API, if it's possible) |
Just putting this here in case of misunderstandings: that was a honest question, I've never seen such a layout and it took me a bit to understand how that fits together in the final package. From my understanding (and after the merge of all code into one package) it seems that all code could live in a single |
The dirty (and shortest) fix is to
Because the current This would also be a completely backwards compatible change (apart from using |
9180ea5
to
e3272c1
Compare
Implmented the "quick and fast" version above. Tested if locally by |
e3272c1
to
bf45a74
Compare
this looks good to me. i understand there is a larger unfinished discussion about refactoring improvements - my thought is that if DbContainer was part of the public api (i would argue it is) then we cannot change it without version increases (maybe even major) so lets deprecate them now, and change the implementation underneath (overriding methods) (that is something we are allowed to do on patch increases). (i just mean in the sense that people should not use DbContainer going forward if we plan to remove it.) |
cfc3b27
to
a45a991
Compare
Added back the tests and also made a check against using sqla during container startup |
After this discussion (with adding _wait_for_ready() and _configure() to the top level class), DBContainer would only contain this:
I'm not sure if this is worth a extra class in the hierarchy, especially because it's unclear to me if that URL can be useful for all DB container or only the ones which are based on the python DB API (=RDBMS ones, not stuff like mongodb or redis): I've no clue if they also can be connected to with a single URL (kafka can not, I think). Given that each container would need to implement the method anyway, one could also make _create_connection_url() a pure function and let each container just declare the method themselves... Anyway: I would appreciate if this conversation could be moved to a separate issue :-) |
a45a991
to
c5e2ccc
Compare
Added the fix to make ruff happy, waiting for workflow approval @alexanderankin @totallyzen |
ill keep an eye on this today but also we have a slack https://slack.testcontainers.org/ where i respond to pings and stuff |
Remove test that was testing sqlalchemy support for driver types Add tests for supported versions of Postgres Modify the `get_connection_url` convenience method to support a driverless url Co-authored-by: Jan Katins <jasc@gmx.net> Co-authored-by: Jason Turim <jason@opscanvas.com>
c5e2ccc
to
69d60f3
Compare
And another try.. rand black and ruff locally, so hopefully no more rounds... @alexanderankin |
ok lets iterate on this:) |
🤖 I have created a release *beep* *boop* --- ## [4.0.1](testcontainers-v4.0.0...testcontainers-v4.0.1) (2024-03-11) ### Features * **postgres:** Remove SqlAlchemy dependency from postgres container ([#445](#445)) ([f30eb1d](f30eb1d)) ### Bug Fixes * **clickhouse:** clickhouse waiting ([#428](#428)) ([902a5a3](902a5a3)) * Close docker client when stopping the docker container ([#380](#380)) ([efb1683](efb1683)) * failing tests for elasticsearch on machines with ARM CPU ([#454](#454)) ([701b23a](701b23a)) * **mongodb:** waiting for container to start (it was not waiting at all before?) ([#461](#461)) ([2c4f171](2c4f171)) * unclosed socket warning in db containers ([#378](#378)) ([cd90aa7](cd90aa7)) * Update the copyright header for readthedocs ([#341](#341)) ([5bef18a](5bef18a)) --- 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> Co-authored-by: David Ankin <daveankin@gmail.com>
🤖 I have created a release *beep* *boop* --- ## [4.0.1](testcontainers-v4.0.0...testcontainers-v4.0.1) (2024-03-11) ### Features * **postgres:** Remove SqlAlchemy dependency from postgres container ([#445](#445)) ([f30eb1d](f30eb1d)) ### Bug Fixes * **clickhouse:** clickhouse waiting ([#428](#428)) ([902a5a3](902a5a3)) * Close docker client when stopping the docker container ([#380](#380)) ([efb1683](efb1683)) * failing tests for elasticsearch on machines with ARM CPU ([#454](#454)) ([701b23a](701b23a)) * go back to 4.0.1 ([#465](#465)) ([1ac8c24](1ac8c24)) * **mongodb:** waiting for container to start (it was not waiting at all before?) ([#461](#461)) ([2c4f171](2c4f171)) * unclosed socket warning in db containers ([#378](#378)) ([cd90aa7](cd90aa7)) * Update the copyright header for readthedocs ([#341](#341)) ([5bef18a](5bef18a)) --- 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> Co-authored-by: David Ankin <daveankin@gmail.com>
…estcontainers#445) Updates the pg testcontainer implementation to not use (and not install) SQLAlchemy nor psycopg2. Closes: testcontainers#340 Closes: testcontainers#336 Closes: testcontainers#320 --------- Co-authored-by: Jason Turim <jason@opscanvas.com>
🤖 I have created a release *beep* *boop* --- ## [4.0.1](testcontainers/testcontainers-python@testcontainers-v4.0.0...testcontainers-v4.0.1) (2024-03-11) ### Features * **postgres:** Remove SqlAlchemy dependency from postgres container ([testcontainers#445](testcontainers#445)) ([f30eb1d](testcontainers@f30eb1d)) ### Bug Fixes * **clickhouse:** clickhouse waiting ([testcontainers#428](testcontainers#428)) ([902a5a3](testcontainers@902a5a3)) * Close docker client when stopping the docker container ([testcontainers#380](testcontainers#380)) ([efb1683](testcontainers@efb1683)) * failing tests for elasticsearch on machines with ARM CPU ([testcontainers#454](testcontainers#454)) ([701b23a](testcontainers@701b23a)) * **mongodb:** waiting for container to start (it was not waiting at all before?) ([testcontainers#461](testcontainers#461)) ([2c4f171](testcontainers@2c4f171)) * unclosed socket warning in db containers ([testcontainers#378](testcontainers#378)) ([cd90aa7](testcontainers@cd90aa7)) * Update the copyright header for readthedocs ([testcontainers#341](testcontainers#341)) ([5bef18a](testcontainers@5bef18a)) --- 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> Co-authored-by: David Ankin <daveankin@gmail.com>
🤖 I have created a release *beep* *boop* --- ## [4.0.1](testcontainers/testcontainers-python@testcontainers-v4.0.0...testcontainers-v4.0.1) (2024-03-11) ### Features * **postgres:** Remove SqlAlchemy dependency from postgres container ([testcontainers#445](testcontainers#445)) ([f30eb1d](testcontainers@f30eb1d)) ### Bug Fixes * **clickhouse:** clickhouse waiting ([testcontainers#428](testcontainers#428)) ([902a5a3](testcontainers@902a5a3)) * Close docker client when stopping the docker container ([testcontainers#380](testcontainers#380)) ([efb1683](testcontainers@efb1683)) * failing tests for elasticsearch on machines with ARM CPU ([testcontainers#454](testcontainers#454)) ([701b23a](testcontainers@701b23a)) * go back to 4.0.1 ([testcontainers#465](testcontainers#465)) ([1ac8c24](testcontainers@1ac8c24)) * **mongodb:** waiting for container to start (it was not waiting at all before?) ([testcontainers#461](testcontainers#461)) ([2c4f171](testcontainers@2c4f171)) * unclosed socket warning in db containers ([testcontainers#378](testcontainers#378)) ([cd90aa7](testcontainers@cd90aa7)) * Update the copyright header for readthedocs ([testcontainers#341](testcontainers#341)) ([5bef18a](testcontainers@5bef18a)) --- 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> Co-authored-by: David Ankin <daveankin@gmail.com>
Updates the pg testcontainer implementation to not use (and not install) SQLAlchemy nor psycopg2.
Closes: #340
Closes: #336
Closes: #320