Also replace node types when key with underscore changed
Previously all keys starting with an underscore were ignored (so changes to _created wouldn't count as "different"), but this clashes with saving Markdown output to _xxx_html keys.
This commit is contained in:
@@ -172,7 +172,7 @@ def doc_diff(doc1, doc2, *, falsey_is_equal=True, superkey: str = None):
|
|||||||
|
|
||||||
Yields changes as (key, value in doc1, value in doc2) tuples, where
|
Yields changes as (key, value in doc1, value in doc2) tuples, where
|
||||||
the value can also be the DoesNotExist class. Does not report changed
|
the value can also be the DoesNotExist class. Does not report changed
|
||||||
private keys (i.e. starting with underscores).
|
private keys (i.e. the standard Eve keys starting with underscores).
|
||||||
|
|
||||||
Sub-documents (i.e. dicts) are recursed, and dot notation is used
|
Sub-documents (i.e. dicts) are recursed, and dot notation is used
|
||||||
for the keys if changes are found.
|
for the keys if changes are found.
|
||||||
@@ -181,6 +181,8 @@ def doc_diff(doc1, doc2, *, falsey_is_equal=True, superkey: str = None):
|
|||||||
function won't report differences between DoesNotExist, False, '', and 0.
|
function won't report differences between DoesNotExist, False, '', and 0.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
private_keys = {'_id', '_etag', '_deleted', '_updated', '_created'}
|
||||||
|
|
||||||
def combine_key(some_key):
|
def combine_key(some_key):
|
||||||
"""Combine this key with the superkey.
|
"""Combine this key with the superkey.
|
||||||
|
|
||||||
@@ -200,7 +202,7 @@ def doc_diff(doc1, doc2, *, falsey_is_equal=True, superkey: str = None):
|
|||||||
|
|
||||||
if isinstance(doc1, dict) and isinstance(doc2, dict):
|
if isinstance(doc1, dict) and isinstance(doc2, dict):
|
||||||
for key in set(doc1.keys()).union(set(doc2.keys())):
|
for key in set(doc1.keys()).union(set(doc2.keys())):
|
||||||
if isinstance(key, str) and key[0] == '_':
|
if key in private_keys:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val1 = doc1.get(key, DoesNotExist)
|
val1 = doc1.get(key, DoesNotExist)
|
||||||
|
@@ -484,7 +484,13 @@ def replace_pillar_node_type_schemas(project_url=None, all_projects=False, missi
|
|||||||
projects_collection = current_app.db()['projects']
|
projects_collection = current_app.db()['projects']
|
||||||
will_would = 'Will' if go else 'Would'
|
will_would = 'Will' if go else 'Would'
|
||||||
|
|
||||||
|
projects_changed = projects_seen = 0
|
||||||
|
|
||||||
def handle_project(proj):
|
def handle_project(proj):
|
||||||
|
nonlocal projects_changed, projects_seen
|
||||||
|
|
||||||
|
projects_seen += 1
|
||||||
|
|
||||||
orig_proj = copy.deepcopy(proj)
|
orig_proj = copy.deepcopy(proj)
|
||||||
proj_id = proj['_id']
|
proj_id = proj['_id']
|
||||||
if 'url' not in proj:
|
if 'url' not in proj:
|
||||||
@@ -526,6 +532,8 @@ def replace_pillar_node_type_schemas(project_url=None, all_projects=False, missi
|
|||||||
proj_has_difference = True
|
proj_has_difference = True
|
||||||
log.info(' %30r: %r → %r', key, val1, val2)
|
log.info(' %30r: %r → %r', key, val1, val2)
|
||||||
|
|
||||||
|
projects_changed += proj_has_difference
|
||||||
|
|
||||||
if go and proj_has_difference:
|
if go and proj_has_difference:
|
||||||
# Use Eve to PUT, so we have schema checking.
|
# Use Eve to PUT, so we have schema checking.
|
||||||
db_proj = remove_private_keys(proj)
|
db_proj = remove_private_keys(proj)
|
||||||
@@ -546,6 +554,9 @@ def replace_pillar_node_type_schemas(project_url=None, all_projects=False, missi
|
|||||||
if all_projects:
|
if all_projects:
|
||||||
for project in projects_collection.find({'_deleted': {'$ne': True}}):
|
for project in projects_collection.find({'_deleted': {'$ne': True}}):
|
||||||
handle_project(project)
|
handle_project(project)
|
||||||
|
log.info('%s %d of %d projects',
|
||||||
|
'Changed' if go else 'Would change',
|
||||||
|
projects_changed, projects_seen)
|
||||||
return
|
return
|
||||||
|
|
||||||
if project_url:
|
if project_url:
|
||||||
|
Reference in New Issue
Block a user