Repository navigation
Description
Problem
In the user sync from #174, a failed store_entity call is reported as a success, and User: redirects are still written for the items that were not stored.
_store_usersadds each title toreport.createdorreport.updatedwhile it builds the entities, beforestore_entityruns:
osw-python/src/osw/tools/user_sync/sync.py
Lines 110 to 122 in 02570c8
for resolved in resolution.resolved: proposed = resolved.change.proposed try: if resolved.action == "create": entities.append(build_user(proposed)) report.created.append(proposed.full_page_title) elif resolved.action == "update": entities.append( apply_update( resolved.change.existing, proposed, resolved.apply_fields ) ) report.updated.append(proposed.full_page_title) - When
store_entityraises, the exception is caught and recorded only asreport.failed["store"]. The titles stay increatedandupdated:
osw-python/src/osw/tools/user_sync/sync.py
Lines 127 to 138 in 02570c8
if entities: try: osw.store_entity( OSW.StoreEntityParam( entities=entities, overwrite=True, remove_empty=remove_empty, edit_comment="user-sync", ) ) except Exception as exc: # pragma: no cover - network failure path report.failed["store"] = str(exc) run_user_syncthen calls_create_redirectsfor every resolved user, whether its item was stored or not:
osw-python/src/osw/tools/user_sync/sync.py
Lines 224 to 226 in 02570c8
_store_users(osw, resolution, report, remove_empty=not config.prune) if config.create_redirects: _create_redirects(osw, resolution, report)
Result: report.summary() counts items as created or updated that are not on the wiki, and User:<username> redirects point to pages that may not exist. Only _verify can detect the missing items afterwards.
The same applies to organizations: report.organizations is set only on success, but users that link to an organization are still stored when the organization store failed:
osw-python/src/osw/tools/user_sync/sync.py
Lines 93 to 103 in 02570c8
| def _store_organizations(osw: Any, org_map, report: SyncReport) -> None: | |
| if not org_map: | |
| return | |
| entities = [build_organization(org) for org in org_map.values()] | |
| try: | |
| osw.store_entity( | |
| OSW.StoreEntityParam(entities=entities, edit_comment="user-sync: orgs") | |
| ) | |
| report.organizations = [org.full_page_title for org in org_map.values()] | |
| except Exception as exc: # pragma: no cover - network failure path | |
| report.failed["organizations"] = str(exc) |
Expected
- A title is counted as created or updated only after
store_entitystored it. store_entityraisesOSW.StoreEntityPartialErroron a partial failure. Itsstoredattribute lists the stored titles and itsfailedattribute maps each failed title to its exception, so the sync can count the stored titles and record each failed title inreport.failed.- Redirects are written only for users whose item was stored or already existed.
Tests
The only test in tests/tools/test_user_sync_sync.py that runs the sync is the dry-run test. No test runs an accepted sync, a failed store, the redirects after a failed store, or a sync with prune=True.
Activity
fix(user-sync): count and redirect only stored items (#224)