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
Fix #443 object merge with same value on same level keys #444
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# [bug] Setting values being stripped out after merge | ||
|
||
* created by @daviddavis on 2020-10-07 14:13:58 +0000 UTC | ||
|
||
**Describe the bug** | ||
I'm seeing where values are being stripped out of settings. This is on dynaconf 3.1.1 with Python 3.7.7. | ||
|
||
**To Reproduce** | ||
Run this code: | ||
|
||
```python | ||
from dynaconf.utils.boxing import DynaBox | ||
from dynaconf.utils import object_merge | ||
|
||
existing_data = DynaBox({"DATABASES": {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'HOST': 'localhost', 'PASSWORD': 'pulp', 'NAME': 'pulp', 'USER': 'pulp'}}}) | ||
new_data = DynaBox({'DATABASES': {'default': {'USER': 'postgres'}}}) | ||
split_keys = ['DATABASES', 'default', 'USER'] | ||
object_merge(old=existing_data, new=new_data, full_path=split_keys) | ||
``` | ||
|
||
The output: | ||
|
||
``` | ||
<Box: {'DATABASES': {'default': {'USER': 'postgres', 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'HOST': 'localhost'}}}> | ||
``` | ||
|
||
Notice that NAME and PASSWORD keys have been dropped. | ||
|
||
**Expected behavior** | ||
I would expect the final settings dict to be: | ||
|
||
``` | ||
{"DATABASES": {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'HOST': 'localhost', 'PASSWORD': 'pulp', 'NAME': 'pulp', 'USER': 'postgres'}}} | ||
``` | ||
|
||
## Comments: | ||
|
||
### comment by @rochacbruno on 2020-10-07 14:31:15 +0000 UTC | ||
|
||
The bug is in | ||
|
||
https://github.com/rochacbruno/dynaconf/blob/8998cac224a985dc8bb783f2a5abd71ff4e6769c/dynaconf/utils/__init__.py#L45 | ||
|
||
As all the values are `pulp` it is wrongly using `is` to compare and `"pulp" is "pulp"` will always be `True` regardless the key it is in. | ||
|
||
```py | ||
>>> s1 = "pulp" | ||
>>> s2 = "pulp" | ||
>>> s1 is s2 | ||
True | ||
``` | ||
|
||
I will need to include the full path to the key on the comparison or change the `DynaBox` in a way that each value gets its own identity even if the value is the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dynaconf.utils import object_merge | ||
from dynaconf.utils.boxing import DynaBox | ||
|
||
existing_data = DynaBox( | ||
{ | ||
"DATABASES": { | ||
"default": { | ||
"ENGINE": "django.db.backends.postgresql_psycopg2", | ||
"HOST": "localhost", | ||
"PASSWORD": "pulp", | ||
"NAME": "pulp", | ||
"USER": "pulp", | ||
} | ||
} | ||
} | ||
) | ||
assert existing_data["DATABASES"]["default"]["USER"] == "pulp" | ||
|
||
new_data = DynaBox({"DATABASES": {"default": {"USER": "postgres"}}}) | ||
split_keys = ["DATABASES", "default", "USER"] | ||
new = object_merge(old=existing_data, new=new_data, full_path=split_keys) | ||
|
||
assert new["DATABASES"]["default"]["USER"] == "postgres" | ||
assert new["DATABASES"]["default"]["NAME"] == "pulp" | ||
assert new["DATABASES"]["default"]["PASSWORD"] == "pulp" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 line is still
buggy
as this comparison cannot handleNone
types.To improve this we need to create a way to have a unique signature for each value.