fix(ingest/repository-documents): set the document lifecycle stage on import
Summary
Documents have two fields that say whether they are published: status.lifecycleStage (which wins when set) and the legacy documentInfo.status.state. The stage is the field that decides, and some DataHub servers show a document in the Documents tree only when its stage is PUBLISHED. Ingestion wrote only the legacy state, so imported documents had no stage.
A connector owns the stage of the documents it emits. It sets the stage on every emit, the same way it sets the title or the body. A stage changed in the UI does not survive the next ingestion of a connector-owned document. This applies to documents only: it is not a rule for other entity types, where connectors may need to leave a stage a person set alone.
Document SDK: the stage and the legacy state are written together.
create_document/create_external_document: PUBLISHED writesstatuswith theurn:li:lifecycleStageType:PUBLISHEDstage. UNPUBLISHED writes no stage, so the legacy UNPUBLISHED state decides visibility. Every connector that builds documents through the SDK (Hex, Confluence, Google Drive, unstructured, the repository sources) gets this.set_status/publish/unpublish: PUBLISHED sets the PUBLISHED stage. UNPUBLISHED keeps an existing non-published stage (DRAFT, IN_REVIEW, ...) and otherwise clears the stage, so a stale PUBLISHED stage can't keep an unpublished document visible. Each change is stamped inlifecycleLastUpdated, and these methods take an optionalactor.- New read-only
Document.lifecycle_stageproperty. write_status=Falseoncreate_document/create_external_documentskips thestatusaspect, for writers that managestatusthemselves and keep a stage set elsewhere.
Repository documents importer (GitHub and GitLab). In the shared repository_documents/source.py:
- Resurrected files and folders (soft-deleted, back in the repository) are emitted with
Status(removed=False, lifecycleStage=PUBLISHED). Before, they got a bareStatus(removed=False), which replaced the aspect and left no stage. Nothing is read back from the graph. - An existing folder that isn't soft-deleted gets no
statuswrite. A folder has no content to hash, so re-emitting its Status on every run would add a status version and change event per folder per run. New folders get the stage from the SDK on creation. - Built documents keep the
statusthe SDK wrote.
Backfill: documents imported before this change get the stage on the next run. The importer skips a file when its source hash matches the source_content_hash stored on the document. A new OUTPUT_VERSION constant ("2": Status carries the lifecycle stage) is now part of that hash, for plain and OKF files. Each unchanged file is re-imported once on the next run, picks up the PUBLISHED stage, and is skipped again after that. Bump OUTPUT_VERSION whenever the aspects emitted per file change.
EXTRACTION_ALGO_VERSIONandcompute_file_content_hashare unchanged: that hash is also the sync-back contract (content_hash), so bumping it would make every exported page look edited.
The SDK only refers to the PUBLISHED stage, which the default lifecycle-stages.yaml bootstrap creates, so LifecycleStageValidator accepts these writes.
Behaviour notes
- Every document a connector emits through the SDK as PUBLISHED now carries the PUBLISHED stage, replacing any stored stage.
- The first run of a repository source after upgrading re-imports every file once (see Backfill). Later runs skip unchanged files as before. Existing folders are not backfilled. With no stage, their legacy PUBLISHED state decides visibility as before.
- Documented in
docs/how/breaking-changes.md: a stage set on an imported document (ARCHIVED, DEPRECATED, REJECTED, ...) used to survive re-ingestion, becauseAutoStatusAspectProcessoronly patchesremoved. Now it is reset to PUBLISHED the next time the connector writes the document. - The hex, github-documents and gitlab-documents goldens change in the document
statusaspects (PUBLISHED stage) and, for the repository sources, thesource_content_hashvalues.
Testing
tests/unit/sdk/test_document.py: stage on create,write_status=Falsewriting nostatus, publish/unpublish keeping the stage in sync, DRAFT kept on unpublish.tests/unit/ingestion/source/github_documents/test_github_documents_source.py: an existing folder gets nostatuswrite; a soft-deleted folder and a resurrected file with a stored DRAFT get PUBLISHED; a changed file's status carries the PUBLISHED stage; a hash from an older output version re-imports the file;OUTPUT_VERSIONchanges both the plain and the OKF hash.- Regenerated the github-documents, gitlab-documents and hex goldens.
- Ruff and mypy clean.
Checklist
- The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
- Tests for the changes have been added/updated
- Docs related to the changes have been added/updated (n/a)
- Breaking Changes entry in
docs/how/breaking-changes.md