Merge dev → main: per-post stdout diagnostics + post-field write DRY (#842/#753) #106

Merged
bvandeusen merged 2 commits from dev into main 2026-06-14 23:45:39 -04:00
Showing only changes of commit 0d51b93aa7 - Show all commits
+25 -24
View File
@@ -739,6 +739,29 @@ class Importer:
self.session.commit()
return ImportResult(status="refreshed", image_id=existing.id)
def _apply_post_fields(self, post: Post, sd) -> None:
"""Write a parsed sidecar's post-level fields onto a Post — the SINGLE
predicate shared by BOTH ingest paths: the per-media path (_apply_sidecar)
and the post-record path (upsert_post_record). Fill-with-non-empty:
parse_sidecar yields None for empty values, so a None field is left
untouched (an empty feed body never wipes a populated one). raw_metadata +
external-link sync always run (latest snapshot). Keeping ONE copy stops
the two paths from diverging on how a post body/links get stored — they
were verbatim duplicates (#842 DRY pass; see [[feedback_preview_apply_parity]]).
"""
if sd.post_url is not None:
post.post_url = sd.post_url
if sd.post_title is not None:
post.post_title = sd.post_title
if sd.post_date is not None:
post.post_date = sd.post_date
if sd.description is not None:
post.description = sd.description
if sd.attachment_count is not None:
post.attachment_count = sd.attachment_count
post.raw_metadata = sd.raw
self._sync_external_links(post)
def upsert_post_record(
self, sidecar: Path, *, artist: Artist | None = None,
source: Source | None = None,
@@ -785,18 +808,7 @@ class Importer:
)
if post.artist_id is None:
post.artist_id = artist.id
if sd.post_url is not None:
post.post_url = sd.post_url
if sd.post_title is not None:
post.post_title = sd.post_title
if sd.post_date is not None:
post.post_date = sd.post_date
if sd.description is not None:
post.description = sd.description
if sd.attachment_count is not None:
post.attachment_count = sd.attachment_count
post.raw_metadata = sd.raw
self._sync_external_links(post)
self._apply_post_fields(post, sd)
self.session.commit()
return True
@@ -1098,18 +1110,7 @@ class Importer:
external_post_id=epid,
artist_id=artist.id,
)
if sd.post_url is not None:
post.post_url = sd.post_url
if sd.post_title is not None:
post.post_title = sd.post_title
if sd.post_date is not None:
post.post_date = sd.post_date
if sd.description is not None:
post.description = sd.description
if sd.attachment_count is not None:
post.attachment_count = sd.attachment_count
post.raw_metadata = sd.raw
self._sync_external_links(post)
self._apply_post_fields(post, sd)
# Race-safe (image_record_id, post_id) upsert — mirrors the
# _find_or_create_source/post savepoint pattern. The plain