Skip to content

doc_copy[key] = copy.deepcopy(val) - #643

Open
Bezbran wants to merge 6 commits into
mongomock:developfrom
Bezbran:develop
Open

Bezbran wants to merge 6 commits into
mongomock:developfrom
Bezbran:develop

Conversation

@Bezbran

@Bezbran Bezbran commented Jul 13, 2020

Copy link
Copy Markdown

Look in this case:
first_call = mongo_c.get_collection("collectionA").find_one({"search_field": "search_value"}, projection={"som_field":False})
second_call = mongo_c.get_collection("collectionA").find_one({"search_field": "search_value"}, projection={"som_field":False})

and there is an item with {"search_field": "search_value","som_field":"abc","some_field2":{"inner_field1":"original value"}}.

if we will do something like:
first_call ["some_field2"]["inner_field1"] = "new_value"
we will change the value of the second_call too:
print(second_call ["some_field2"]["inner_field1"] )

new_value
which is wrong!!!

Look in this case:
first_call = mongo_c.get_collection("collectionA").find_one({"search_field": "search_value"}, projection={"som_field":False})
second_call = mongo_c.get_collection("collectionA").find_one({"search_field": "search_value"}, projection={"som_field":False})

and there is an item with {"search_field": "search_value","some_filed":"abc","some_field2":{"inner_field1":"original value"}}.

if we will do something like:
first_call ["some_field2"]["inner_field1"] = "new_value"
we will change the value of the second_call  too:
print(second_call ["some_field2"]["inner_field1"] )
>new_value
@codecov

codecov Bot commented Jul 13, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #643 (d620139) into develop (47c7edb) will decrease coverage by 0.48%.
The diff coverage is 100.00%.

❗ Current head d620139 differs from pull request most recent head a8c95d8. Consider uploading reports for the commit a8c95d8 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #643      +/-   ##
===========================================
- Coverage    95.38%   94.89%   -0.49%     
===========================================
  Files           19       17       -2     
  Lines         3639     3290     -349     
===========================================
- Hits          3471     3122     -349     
  Misses         168      168              
Impacted Files Coverage Δ
mongomock/collection.py 91.65% <100.00%> (-0.83%) ⬇️
mongomock/results.py 83.72% <0.00%> (-1.17%) ⬇️
mongomock/filtering.py 98.92% <0.00%> (-0.08%) ⬇️
mongomock/store.py 100.00% <0.00%> (ø)
mongomock/helpers.py 100.00% <0.00%> (ø)
mongomock/__init__.py 100.00% <0.00%> (ø)
mongomock/not_implemented.py
mongomock/codec_options.py
mongomock/aggregate.py 97.41% <0.00%> (+0.22%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47c7edb...a8c95d8. Read the comment docs.

@pcorpet pcorpet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please split your commits in two different Pull Requests.

Also can you update the tests to add the code that shows that the previous code was wrong please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants