Skip to content

Commit e3acb28

Browse files
committed
publisher: rework page property processing
Calls to `get_page_property` should return `None` for non-entries on a page. This was the original intent with the implementation, but final tweaks for initial APIv2 support made the default result a partially populated property instance. This commit cleans up this to restore the original intent to have undefined properties return `None`, as well as updates various locations to use a default property value for each applicable section. Specifically: - `CB_PROP_KEY` returns a prepared empty value dictionary, since the requests will push up a new property change - Property fetching for v2 will return a `None` populated value to explicitly indicate that the requests should support this type of metadata, as well as that Confluence has reported no value exists - Update events will populate with a fallback value `None`, which will be updated with the provided property value for the expected change to the property value. Signed-off-by: James Knight <[email protected]> (cherry picked from commit 8bd8137)
1 parent 2eddfb9 commit e3acb28

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sphinxcontrib/confluencebuilder/publisher.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,9 @@ def get_page(self, page_name, expand='version', status='current'):
601601
props_to_fetch.append('editor')
602602

603603
for prop_key in props_to_fetch:
604-
prop_entry = self.get_page_property(page_id, prop_key)
604+
prop_entry = self.get_page_property(page_id, prop_key, {
605+
'value': None,
606+
})
605607
meta_props[prop_key] = prop_entry
606608

607609
return page_id, page
@@ -700,9 +702,7 @@ def get_page_property(self, page_id, key, default=None):
700702
the property value
701703
"""
702704

703-
props = {
704-
'value': default,
705-
}
705+
props = default
706706

707707
if page_id:
708708
try:
@@ -930,7 +930,9 @@ def store_page(self, page_name, data, parent_id=None):
930930

931931
# fetch known properties (associated with this extension) from the page
932932
page_id = page['id'] if page else None
933-
cb_props = self.get_page_property(page_id, CB_PROP_KEY, {})
933+
cb_props = self.get_page_property(page_id, CB_PROP_KEY, {
934+
'value': {},
935+
})
934936

935937
# calculate the hash for a page; we will first use this to check if
936938
# there is a update to apply, and if we do need to update, we will
@@ -986,8 +988,8 @@ def store_page(self, page_name, data, parent_id=None):
986988

987989
# if we are not force uploading, check if the new page hash matches
988990
# the remote hash; if so, do not publish
989-
if cb_props and not force_publish:
990-
remote_hash = cb_props.get('value', {}).get('hash')
991+
if not force_publish:
992+
remote_hash = cb_props['value'].get('hash')
991993
if new_page_hash == remote_hash:
992994
logger.verbose(f'no changes in page: {page_name}')
993995
return page['id']
@@ -1148,7 +1150,9 @@ def store_page_by_id(self, page_name, page_id, data):
11481150
raise ConfluenceMissingPageIdError(self.space_key, page_id) from ex
11491151

11501152
# fetch known properties (associated with this extension) from the page
1151-
cb_props = self.get_page_property(page_id, CB_PROP_KEY, {})
1153+
cb_props = self.get_page_property(page_id, CB_PROP_KEY, {
1154+
'value': {},
1155+
})
11521156

11531157
# calculate the hash for a page; we will first use this to check if
11541158
# there is a update to apply, and if we do need to update, we will
@@ -1157,8 +1161,8 @@ def store_page_by_id(self, page_name, page_id, data):
11571161

11581162
# if we are not force uploading, check if the new page hash matches
11591163
# the remote hash; if so, do not publish
1160-
if cb_props and not self.config.confluence_publish_force:
1161-
remote_hash = cb_props.get('value', {}).get('hash')
1164+
if not self.config.confluence_publish_force:
1165+
remote_hash = cb_props['value'].get('hash')
11621166
if new_page_hash == remote_hash:
11631167
logger.verbose(f'no changes in page: {page_name}')
11641168
return page_id
@@ -1208,7 +1212,9 @@ def _update_page_properties(self, page_id, properties):
12081212
attempt = 1
12091213
while attempt <= MAX_ATTEMPTS_TO_UPDATE_PROPERTY:
12101214
prop_key = prop['key']
1211-
prop_entry = self.get_page_property(page_id, prop_key)
1215+
prop_entry = self.get_page_property(page_id, prop_key, {
1216+
'value': None,
1217+
})
12121218

12131219
# ignore if the property already matches the desired
12141220
# value

0 commit comments

Comments
 (0)