[SERVER-56352]  Historic dict update should implicitly convert dict to Historic dict Created: 26/Apr/21  Updated: 29/Oct/23  Resolved: 13/May/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Robert Guo (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File mongos_parameter.patch    
Issue Links:
Problem/Incident
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: STM 2021-05-03, STM 2021-05-17, STM 2021-05-31
Participants:
Linked BF Score: 0
Story Points: 1

 Description   

Original description:
The log component verbosity should accept a Historic instead of a regular dict.

We should also audit other places in that file that accept user input and check that dictionaries are converted correctly



 Comments   
Comment by Githook User [ 13/May/21 ]

Author:

{'name': 'Robert Guo', 'email': 'robert.guo@mongodb.com'}

Message: SERVER-56352 allow dictionaries to be implicitly converted to HistoricDict
Branch: master
https://github.com/mongodb/mongo/commit/44b5378cbcb4d84fb4bccda8357287ea785ee631

Comment by Robert Guo (Inactive) [ 13/May/21 ]

Thanks for the illustrative example Raiden! My changes only removed make_historic() for direct assignments to historic (aka "prvalues"), not to variable assignments. This somewhat reduces the risk of dictionaries being modified. Separately, I think the Python reference semantics may not be clear to everyone, especially if innerdict gets reassigned from primitives to/from dict, which could happen for fields like logcomponentverbosity. Since most primitives are not passed by reference, we can encourage users to treat dictionaries as immutable types where possible.

Comment by Raiden Worley (Inactive) [ 12/May/21 ]

Just as a note, I'd originally avoided implicitly converting stored dicts to HistoryDict because it can lead to unintuitive behavior with python reference semantics. For example:

 

outerdict = make_historic({})
innerdict = {"foo": "bar"}
outerdict["inner"] = make_historic(innerdict)
 
innerdict["foo2"] = "bar2"
outerdict["inner"]["foo"] # returns "bar"
outerdict["inner"]["foo2"] # keyerror, would've worked if these were all normal dicts

In the above example, having the make_historic external to the dict forces users to recognize that they're distinct references; having it internal to the set method could've been confusing.

Generated at Thu Feb 08 05:39:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.