Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

logicbomb
Copy link

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 in Postgres.__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 and pip documentation, but couldn't install from github as there is neither setup.py nor pyproject.toml in the root directory.

Jason Turim added 2 commits May 1, 2023 08:45
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
@tillahoffmann tillahoffmann changed the title Issue 336 Remove sqlalchemy dependency from postgres connection check May 4, 2023
Copy link
Collaborator

@tillahoffmann tillahoffmann left a 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:
Copy link
Collaborator

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.

Copy link
Contributor

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... :-)

Copy link
Collaborator

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.

Copy link
Contributor

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
Copy link
Collaborator

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.

@nicos68
Copy link

nicos68 commented Aug 29, 2023

Hi,

any idea when this could be merged ? I’m using peewee as my orm and would love to get rid of that too.

@jankatins
Copy link
Contributor

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 :-/

Copy link
Contributor

@jankatins jankatins left a 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

@jamesbraza
Copy link

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"]
Copy link
Contributor

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)

@dvuletas
Copy link

When this would be expected to be merged?
Thanks!

@jankatins
Copy link
Contributor

@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)?

@totallyzen
Copy link
Collaborator

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 😇 🥺

  • 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)
  • It's possible the same thing as for kafka, I would be happy with that approach, see fix(kafka): wait_for_logs in kafka container to reduce lib requirement #377

@jankatins
Copy link
Contributor

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

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.

@logicbomb
Copy link
Author

logicbomb commented Mar 4, 2024 via email

@jankatins
Copy link
Contributor

I opened #445 for the rebased version.

@alexanderankin
Copy link
Collaborator

closing in favor of #445 for now

alexanderankin pushed a commit that referenced this pull request Mar 10, 2024
…445)

Updates the pg testcontainer implementation to not use (and not install)
SQLAlchemy nor psycopg2.

Closes: #340
Closes: #336
Closes: #320

---------

Co-authored-by: Jason Turim <jason@opscanvas.com>
alexanderankin pushed a commit that referenced this pull request Mar 11, 2024
…445)

Updates the pg testcontainer implementation to not use (and not install)
SQLAlchemy nor psycopg2.

Closes: #340
Closes: #336
Closes: #320

---------

Co-authored-by: Jason Turim <jason@opscanvas.com>
bearrito pushed a commit to bearrito/testcontainers-python that referenced this pull request Mar 30, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design question / is a hard dependency on SqlAlchemy really necessary?
8 participants