Startup crash on shallow Dahua layout: parents[4] resolves to wrong directory #140

Closed
opened 2026-08-12 03:55:56 +00:00 by agent-pi · 2 comments
Collaborator

Bug

During startup scan, _scan_snapshots_for_camera crashes with:

ValueError: Invalid isoformat string: 'AF007D8PAG5B66F'

Only cameras using the shallow Dahua layout trigger this; deep-layout cameras work fine.

Root cause

lifespan.py line 100 uses source_path.parents[4] to find the date directory for pruning. This hard-codes the deep Dahua layout depth (6 levels: cam_root/YYYY-MM-DD/channel/jpg/HH/MM/SS.jpg). The shallow layout is one level shallower (5 levels: cam_root/YYYY-MM-DD/channel/jpg/HH.MM.SS.jpg), so parents[4] lands on cam_root — a serial number directory like AF007D8PAG5B66F, not an ISO date.

Fix

Use snapshot.date (already parsed by the Dahua adapter) and construct the date directory as cam.root / snapshot.date.isoformat() instead of fragile parent traversal. This works identically for both layouts.

## Bug During startup scan, `_scan_snapshots_for_camera` crashes with: ``` ValueError: Invalid isoformat string: 'AF007D8PAG5B66F' ``` Only cameras using the shallow Dahua layout trigger this; deep-layout cameras work fine. ## Root cause `lifespan.py` line 100 uses `source_path.parents[4]` to find the date directory for pruning. This hard-codes the deep Dahua layout depth (6 levels: `cam_root/YYYY-MM-DD/channel/jpg/HH/MM/SS.jpg`). The shallow layout is one level shallower (5 levels: `cam_root/YYYY-MM-DD/channel/jpg/HH.MM.SS.jpg`), so `parents[4]` lands on `cam_root` — a serial number directory like `AF007D8PAG5B66F`, not an ISO date. ## Fix Use `snapshot.date` (already parsed by the Dahua adapter) and construct the date directory as `cam.root / snapshot.date.isoformat()` instead of fragile parent traversal. This works identically for both layouts.
Author
Collaborator

Plan

  1. Replace source_path.parents[4] with cam.root / snapshot.date.isoformat() in _scan_snapshots_for_camera (src/cang/web/lifespan.py line 100)
  2. The snapshot.date field is already parsed by the adapter — no new parsing needed
  3. Same-line date.fromisoformat(date_dir.name) check becomes snapshot.date < today

Branch: fix/issue-140-141-regressions
Commits:

  • :bug: Fix startup crash on shallow Dahua layout by using snapshot.date instead of path traversal
  • :bug: Fix deploy-docs CI regex to accept 4-part micro-calver tags
**Plan** 1. Replace `source_path.parents[4]` with `cam.root / snapshot.date.isoformat()` in `_scan_snapshots_for_camera` (`src/cang/web/lifespan.py` line 100) 2. The `snapshot.date` field is already parsed by the adapter — no new parsing needed 3. Same-line `date.fromisoformat(date_dir.name)` check becomes `snapshot.date < today` **Branch**: `fix/issue-140-141-regressions` **Commits**: - `:bug: Fix startup crash on shallow Dahua layout by using snapshot.date instead of path traversal` - `:bug: Fix deploy-docs CI regex to accept 4-part micro-calver tags`
Author
Collaborator

Plan: use snapshot.date instead of parents[4] for date directory path

Plan: use snapshot.date instead of parents[4] for date directory path
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marvin8/cang#140
No description provided.