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:
Sybren A. Stüvel 2018-03-27 17:56:38 +02:00
parent f22dc4d92a
commit d3ff88e5cf
2 changed files with 15 additions and 2 deletions

View File

@ -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
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
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.
"""
private_keys = {'_id', '_etag', '_deleted', '_updated', '_created'}
def combine_key(some_key):
"""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):
for key in set(doc1.keys()).union(set(doc2.keys())):
if isinstance(key, str) and key[0] == '_':
if key in private_keys:
continue
val1 = doc1.get(key, DoesNotExist)

View File

@ -484,7 +484,13 @@ def replace_pillar_node_type_schemas(project_url=None, all_projects=False, missi
projects_collection = current_app.db()['projects']
will_would = 'Will' if go else 'Would'
projects_changed = projects_seen = 0
def handle_project(proj):
nonlocal projects_changed, projects_seen
projects_seen += 1
orig_proj = copy.deepcopy(proj)
proj_id = proj['_id']
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
log.info(' %30r: %r%r', key, val1, val2)
projects_changed += proj_has_difference
if go and proj_has_difference:
# Use Eve to PUT, so we have schema checking.
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:
for project in projects_collection.find({'_deleted': {'$ne': True}}):
handle_project(project)
log.info('%s %d of %d projects',
'Changed' if go else 'Would change',
projects_changed, projects_seen)
return
if project_url: