Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Lock] MongoDbStore skim non-standard options from uri#37218
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| parse_str($parsedUrl['query'],$query); | ||
| } | ||
| if (null === ($this->options['collection'] ??null) &&isset($query['collection'])) { |
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.
I know this was already the case before your PR, but the precedence looks wrong to me:
the DSN should have higher precedence over options (I just double-checked, that's how the Cache component does also).
/cc@jderusse maybe we should review all DSN parsing logic to ensure the precedence is consistent everywhere
/cc@Nyholm that's a good case forthe DSN component - formalizing this behavior :)
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.
👍 not only in cache and lock.
messenger Doctrine:
$configuration +=$options +$query +static::DEFAULT_OPTIONS;
messenger Redis:
parse_str($parsedUrl['query'],$options);
messenger Sqs
$configuration = ['buffer_size'] =$options['buffer_size'] ?? (int) ($query['buffer_size'] ??self::DEFAULT_OPTIONS['buffer_size']),
messenger amqp
$amqpOptions =array_replace_recursive([],$options,$parsedQuery);
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.
Bad news, we need to fix this. Up for a PR?
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.
@nicolas-grekas In order to change the precedence, I think we should detectdsn /options where a precedence change would cause an effective option change and insteadtrigger_deprecation for now. Then swap the precedence insymfony6.0. Do you want me to add this detection /trigger_deprecation in this PR forLock\Store\MongoDbStore only or should we make a list of ALLdsn /options precedence affected classes and do them in a separate PR?
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.
I've added the precedence change since you guys seem to be classing this as a bug rather than a deprecation in:#37268
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.
There is no way to deprecate this behavior properly. Also this will very unlikely hit anyone. This precedence issue lessens the capabilities of the ops side of things. Basically, having the options take over the DSN means that the source needs to change (the options) instead of some env vars. That's a management issue at this point, and this change fixes a process issue: the env vars should always win to give control to the ops, which are the ones that know better since they're the ones in touch with the effective infra.
TL;DR, this is a bugfix.
e06956a to599c128Compare…derusse)This PR was squashed before being merged into the 5.1 branch.Discussion----------[Lock][Messenger] Fix precedence of DSN options for 5.1| Q | A| ------------- | ---| Branch? | 5.1| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |#37218 (comment)| License | MIT| Doc PR | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 5.1Commits-------9670e9f [Lock][Messenger] Fix precedence of DSN options for 5.1
This PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |#37218 (comment)| License | MIT| Doc PR | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a Fix precendence in 4.4
This PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |symfony/symfony#37218 (comment)| License | MIT| Doc PR | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a759 Fix precendence in 4.4
nicolas-grekas commentedJun 18, 2020
Can you please rebase now that the priority is fixed? |
4df26a9 to523bf2aCompare| privatefunctionskimUri(string$uri):string | ||
| { | ||
| if (false ===$parsedUrl =parse_url($uri)) { | ||
| thrownewInvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid.',$mongo)); |
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.
$mongo is not defined
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.
fixed
| /** | ||
| * Extract default database and collection from given connection uri and remove collection querystring. | ||
| */ | ||
| privatefunctionskimUri(string$uri):string |
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.
I'm not comfortable with this method, a lot of complex logic to extract parameter from URI mixing parse_str and strpos.
Givent the format of the initialDSN is defined by symfony, wouldn't it be safer to build the mongo URI instead?
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.
the reason i chose to use strpos to re-assemble was to simplify the re-assembly. there is no reverse of parse_str in php. seehttps://www.php.net/manual/en/function.parse-url.php#106731
I'm trying not to get too involved with touching the URI. What would you suggest that is simpler?
jderusse commentedJul 1, 2020
@nicolas-grekas LGTM from a lock point of view. I just have concerns about complexity of url generator#37218 (comment) . If you think it's ok you can merge it. |
79fee70 to67912faComparefabpot commentedAug 16, 2020
Thank you@kralos. |
| $prefix =rtrim($prefix,'?'); | ||
| } | ||
| $suffix =substr($uri,$queryStringPos +\strlen($parsedUrl['query'])); | ||
| $uri =$prefix.$newQuery.$suffix; |
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.
@kralos: I only just came across this PR based on a notification in#37180. I understand what this function is attempting to do, but usingparse_str may silently corrupting a connection string with repeatedreadPreferenceTags keys (a valid use case, as explained in theURI options spec).This comment on PHP.net goes into more detail about that.
I think it would be preferable to capture the URI option with a regular expression and then, if anything was found, strip it from the returned string. While collection names have theirown restrictions, for purposes of URI parsing I think it'd be best to use something like/collection=([^&]*)/i.
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 PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |symfony/symfony#37218 (comment)| License | MIT| Doc PR | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a759 Fix precendence in 4.4
Don't allow non-standard connection uri options reach
MongoDB\Client