-
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
Remove sqlalchemy dependency from postgres connection check #340
Conversation
Create a new generic database subclass - DependencyFreeDbContainer 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
Note that Postgres container no longer depends on SqlAlchemy Remove reference to unsupported version of postgres Show an example of using the `driver` parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Do you think we can achieve the same outcome by overriding _connect
for the postgres container and moving the content of _verify_status
into _connect
?
@@ -43,14 +43,30 @@ Getting Started | |||
>>> from testcontainers.postgres import PostgresContainer | |||
>>> import sqlalchemy | |||
|
|||
>>> with PostgresContainer("postgres:9.5") as postgres: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick with 9.5 here. Pinning the version in the docs is to ensure that things don't accidentally break because one of the dependencies changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://www.postgresql.org/support/versioning/, 9.5 is not supported anymore, the oldest supported version is 11. My suggestion would be to go with 15 and then have another 5 years until the docs have to be changed... :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, let's bump to 15.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... so now 16 :-)
README.rst
Outdated
>>> with PostgresContainer("postgres:9.5") as postgres: | ||
... engine = sqlalchemy.create_engine(postgres.get_connection_url()) | ||
>>> with PostgresContainer("postgres:latest") as postgres: | ||
... psql_url = postgres.get_connection_url() # postgresql+psycopg2://test:test@localhost:61472/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the comment because the url will vary depending on the environment.
Hi, any idea when this could be merged ? I’m using peewee as my orm and would love to get rid of that too. |
This could also remove the hard dependency on psycopg2 which is slowly superseded by psycopg (v3). At least for us it's now the only package which pulls in the psycopg2 binary :-/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually needs to remove the dependencies on sqlalchemy and psycopg2
Hello friends, random person from the internet. If this feature was supported, it would be pretty nice. For those involved, if you could forward it (seems the developer needed some CI workflow manually triggered), it would be much appreciated 🙏 |
for row in result: | ||
assert row[0].lower().startswith("postgresql 9.5") | ||
# https://www.postgresql.org/support/versioning/ | ||
supported_versions = ["11", "12", "13", "14", "latest"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add 15 and 16 and maybe remove 11 (not supported anymore)
When this would be expected to be merged? |
@logicbomb Will you find time to get this running on top of the current main branch? If not: would you mind if I take this and rebase (or rework, if needed) and open it as a new PR (I will keep your handle as co-author on the commit)? |
Thanks for the activity, mate! I personally wouldn't mind you taking this on (my default attitude is "people are long gone" unless proven otherwise). However, if I could ask for a tweak 😇 🥺
|
So what's the alternative (in the order of my preference, best to lowest)?
This is exactly what this PR does :-) It uses both logs and pg_isready to check instead of opening a connection. It's still missing that the dependency can be removed. |
Hi Jen,
Sorry for the late reply, I'm happy for you to take it over - i'm working
on too many things atm.
jt
…On Mon, Mar 4, 2024 at 5:09 AM Jan Katins ***@***.***> wrote:
Make it not be in generic.py. These "db containers" assume a certain URL
format, but is it worth it to have an entire class
just for this? (I won't hide my distaste over DbContainer and why it is in
core in the first place)
So what's the alternative (in the order of my preference, best to lowest)?
- Move it to a different file?
- Make all the db container implement ´_create_connection_url()`?
- Add a different layer, like singledispatch to turn the container
into an URL?
It's possible the same thing as for kafka, I would be happy with that
approach, see
#377 <#377>
This is exactly what this PR does :-) It uses both logs and pg_isready to
check instead of opening a connection. It's still missing that the
dependency can be removed.
—
Reply to this email directly, view it on GitHub
<#340 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAASJJIOIKAHHWUN7HJNC4TYWRB6VAVCNFSM6AAAAAAXITOD2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZWGIZDGMJYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I opened #445 for the rebased version. |
closing in favor of #445 for now |
…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 decided to include both the log check & the
pg_isready
check, as it seems they both need to be successful in order to enure the database is running.I don't think the
driver
parameter belongs inPostgres.__init__
method, as it's only used when building the connection string, but I didn't want to introduce any breaking changes.Also, I am pretty new to python and was having trouble adding my fork of the project as a package to an external test project. It would be nice if there were some guidance on that in the README. I tried following the instructions in both the
poetry
andpip
documentation, but couldn't install from github as there is neithersetup.py
norpyproject.toml
in the root directory.