Skip to content

[Messenger] Doctrine Transport: Support setting auto_setup from DSN #32392

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

Merged
merged 1 commit into from
Jul 8, 2019
Merged

[Messenger] Doctrine Transport: Support setting auto_setup from DSN #32392

merged 1 commit into from
Jul 8, 2019

Conversation

bendavies
Copy link
Contributor

@bendavies bendavies commented Jul 5, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

It was not possible to set auto_setup via the dsn, as the result would always be a string, resulting in setup always being performed because a bool is required.
The same was true if auto_setup was provided in options as a string.

I've fixed ensuring that the final configuration contains a bool for auto_setup.

Additionally, constructing the configuration was overly complex and hard to grok, so I've hopefully simplified it as part of this PR.

As an aside the three transports all do configuration construction in different ways with varying styles. It would be nice to neaten them up.

@bendavies
Copy link
Contributor Author

travis failure seems unrelated.

],
// test options from options array wins over options from dsn
[
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal',
'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal&auto_setup=true',
Copy link
Member

Choose a reason for hiding this comment

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

Why not use 1 and 0 instead?

Copy link
Contributor Author

@bendavies bendavies Jul 8, 2019

Choose a reason for hiding this comment

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

no reason other than the docs are written with true and false everywhere, and it matches the yaml.
I can add another test covering that 1 and 0 are handled correctly?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, supporting true and false is a mistake (I mean, there are strings). When using a query string, 0 and 1 is the "native" way to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, i'm not precious either way, but note that boolean strings are also supported in the AMQP transport, i.e amqp://localhost?persistent=true

what do you want to do?

Copy link
Contributor Author

@bendavies bendavies Jul 8, 2019

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think consistency is the key here. If we are already supporting true/false elsewhere, let's support it here. Adding support for 1/0 would be nice as well.

We don't have a generic way of handling DSNs, but as we are now using them in many different components, it probably makes sense to create something? Could it be a new component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added covering test for 0/1

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

auto_setup=1 seems missing in the tests.

@bendavies
Copy link
Contributor Author

Added specifically.

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

@bendavies Would you like to have a look at creating a DSN component? The first step would be to have a look at all implementations (like Messenger, Cache, Mailer, ...) and see if we could have a standalone component that would cover all needs.

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

Thank you @bendavies.

@fabpot fabpot merged commit 213dfd1 into symfony:4.3 Jul 8, 2019
fabpot added a commit that referenced this pull request Jul 8, 2019
… from DSN (bendavies)

This PR was squashed before being merged into the 4.3 branch (closes #32392).

Discussion
----------

[Messenger] Doctrine Transport: Support setting auto_setup from DSN

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |    <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |  <!-- required for new features -->

It was not possible to set `auto_setup` via the dsn, as the result would always be a string, resulting in setup always being performed because a bool is required.
The same was true if `auto_setup` was provided in `options` as a string.

I've fixed ensuring that the final configuration contains a bool for `auto_setup`.

Additionally, constructing the `configuration` was overly complex and hard to grok, so I've hopefully simplified it as part of this PR.

As an aside the three transports all do configuration construction in different ways with varying styles. It would be nice to neaten them up.

Commits
-------

213dfd1 [Messenger] Doctrine Transport: Support setting auto_setup from DSN
@bendavies
Copy link
Contributor Author

@bendavies Would you like to have a look at creating a DSN component? The first step would be to have a look at all implementations (like Messenger, Cache, Mailer, ...) and see if we could have a standalone component that would cover all needs.

@fabpot it seems there is a good usecase for a new component.
I'm afraid I'm a bit time strapped at the moment however.
Also, It would be quite a small component, and I'd really struggle to create something that wasn't a complete ripoff of enqueues component, as I use it extensively.

@Simperfit
Copy link
Contributor

@bendavies @fabpot I have time to do it if you want to :)

@jderusse
Copy link
Member

@fabpot Should I reopen #24267 ?

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.

6 participants