Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Skip a connection to execute set_config if the vendor is not postgresql #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

askerka
Copy link

@askerka askerka commented Dec 29, 2022

No description provided.

@funkybob
Copy link
Contributor

Given this package is explicitly for integration with Postgres, could you please elaborate under which conditions the vendor would not be postgresql?

@askerka
Copy link
Author

askerka commented Dec 29, 2022

Given this package is explicitly for integration with Postgres, could you please elaborate under which conditions the vendor would not be postgresql?

Easy. Django supports Multiple databases, and one of them could be not Postgres while the one that is used by the package is Postgres.

But this hook is executed on every established connection even if that is not related to the package.

@funkybob
Copy link
Contributor

Makes sense.

ISTM the better solution, then, would be to find a way to ensure this is only run on the desired database entry. Perhaps an optional setting?

@askerka
Copy link
Author

askerka commented Dec 29, 2022

OK, let me try to find another way how we can achieve this

@askerka
Copy link
Author

askerka commented Dec 30, 2022

Hi @funkybob

Please, have a look.

The PR is quite heavy right now, but most of it is testing files, they can be removed.

The main changes are settings parsing, and DATABASE_ALIAS setting instead of a Postgres URL. This allows us to reuse the same database connection which is used for the migration which is important.

I separated settings to make it easier to work with, IMHO.

Let me know if you are OK with this approach.

@askerka askerka force-pushed the master branch 4 times, most recently from b92151b to 2fa3bbf Compare January 5, 2023 01:57
Comment on lines +34 to +41
3. Add database router in settings.py if you support multiple databases

.. code-block:: python

DATABASE_ROUTERS = [
...
'django_dramatiq_pg.router.Router',
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this complexity of the router?

Surely the migration itself can check schema_editor.connection ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the router, the migration will be applied to the default alias In the case of multiple database support.

So the router is required in case the DB alias is not "default".

Comment on lines -98 to -99
DRAMATIC_BROKER['OPTIONS']
Arguments to pass to the Broker.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you deliberately remove this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is not necessary anymore because we use the alias to the Django database connection instead of a custom URL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you believe it's not possible to want to pass any other options to the Broker?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just assumed the intention based on the code and documentation.
Let me go through the available broker options.

pool=None,
url="",
results=True,
schema=None,
table=None,
middleware=None
  1. pool should be a ThreadedConnectionPool instance that is impossible without additional code just pass as a param
  2. url we construct from DATABASE_ALIAS
  3. schema and table are already hardcoded in the code in the BackgroundJob.Meta.db_table as default broker values (dramatiq and queue respectively) and previously they were hardcoded as BackgroundJob.Meta.db_table and literal in the signal handler. So passing the different values would cause the problem without changing the code of the migration and SQL script
  4. middleware parsed from the MIDDLEWARE
  5. results is used to configure Results results middleware with PostgresBackend. This can be achieved via MIDDLEWARE or left result=True as it is.

As the result, the only meaningful and available option for the broker is the results variable which can be:

  • left as is
  • placed in a separate variable
  • added as separate middleware

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@funkybob Did I address your concerns?

@askerka
Copy link
Author

askerka commented Jan 5, 2023

@funkybob
Eventually, we don't need a signal at all, we just need to specify the qualified table name

db_table = '"dramatiq"."queue"'

@askerka
Copy link
Author

askerka commented Jan 10, 2023

Hi @funkybob
Do you have time to review the PR?

@askerka
Copy link
Author

askerka commented Jan 16, 2023

Hi @funkybob
The review unexpectedly takes a lot of time. Please let me know if you need any help.
I understand if you are not willing to accept it. If this is the case, please, provide a license under what the library is published, and I'll create a separate fork.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants