Skip to content

Commit b08102d

Browse files
authored
Merge pull request #13 from CIAT-DAPA/develop
refactor: improve bulletin retrieval by handling duplicate slugs and …
2 parents d92fd0e + 82d7ff7 commit b08102d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/api/bulletins_management.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,16 @@ def get_current_version_published_by_slug(
307307
Returns 404 if the bulletin doesn't exist or is not published.
308308
"""
309309

310-
# Get bulletin master without authentication
311-
bulletin_master = bulletins_master_service._get_by_field(field="name_machine", value=bulletinSlug)
312-
if not bulletin_master:
310+
# There may be duplicated slugs in historical data, so pick a published
311+
# bulletin that also has a current_version_id.
312+
bulletin_masters = bulletins_master_service.get_all(
313+
filters={"name_machine": bulletinSlug, "status": StatusBulletin.PUBLISHED}
314+
)
315+
if not bulletin_masters:
313316
raise HTTPException(status_code=404, detail="Bulletin not found")
314-
315-
bulletin_master = bulletin_master[0]
316-
317-
# Verify the bulletin is PUBLISHED (security check for public access)
318-
if bulletin_master.status != StatusBulletin.PUBLISHED:
317+
318+
bulletin_master = next((b for b in bulletin_masters if b.current_version_id), None)
319+
if not bulletin_master:
319320
raise HTTPException(status_code=404, detail="Bulletin not found")
320321

321322
bulletin_id = str(bulletin_master.id)

0 commit comments

Comments
 (0)