question 451 Reliable Data Pipelines · easy
Validate a repository record
Repository records arrive from an export before they are joined with events. Check each one against its contract and report every problem, so a bad export is caught at the door.
Function
repo_problems(repo)repo_ida whole number greater than 0 (
True/False don't count) → otherwise "repo_id: expected a positive int"nametext of the form
owner/name: exactly one / with text on both sides → otherwise "name: expected owner/name"languagetext or
None → otherwise "language: expected text or None"stars_beforea whole number ≥ 0 (not a bool) → otherwise
"stars_before: expected a count"Returnsthe problems in the order of the fields above; a missing field counts as
None; [] for a good recordExamples
callrepo_problems({'repo_id': 600000997, 'name': 'quill-data/quickstore', 'language': 'Python', 'stars_before': 37})returns[]
callrepo_problems({'repo_id': '600002991', 'name': 'cloudstore', 'language': None, 'stars_before': -1})returns['repo_id: expected a positive int', 'name: expected owner/name', 'stars_before: expected a count']
callrepo_problems({'repo_id': 600001994, 'name': 'nimbus-io/stream-router', 'language': 3, 'stars_before': 46})returns['language: expected text or None']