Skip to content

Fix/cache empty repolist error handling - #1209

Draft
EngCaioFonseca wants to merge 3 commits into
devfrom
fix/cache-empty-repolist-error-handling
Draft

Fix/cache empty repolist error handling#1209
EngCaioFonseca wants to merge 3 commits into
devfrom
fix/cache-empty-repolist-error-handling

Conversation

@EngCaioFonseca

@EngCaioFonseca EngCaioFonseca commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Pull Request Change Description

Summary

Fixes four issues in PostgreSQL data-access and startup error handling. The changes are local and introduce no schema, dependency, or callback-graph changes.

Changes

1. Handle empty repository selections

repo-choices initially contains [], but its callbacks still run. Psycopg2 converted the empty sequence into IN (), causing invalid SQL during initial page loads.

  • get_uncached() now returns [] immediately.
  • retrieve_from_cache() uses IN (NULL) to return zero rows while preserving DataFrame columns.
  • Heatmap and repository-overview callbacks now return cleared or no-data states when no repository is selected.
  • get_default_repo_with_data() now returns None instead of indexing an empty list.

This is handled at the data and callback boundaries rather than with prevent_initial_call, which would break navigation with selections restored from session storage.

2. Preserve database error causes

AugurManager.run_query() previously caught every exception and discarded its cause.

It now:

  • Catches only Exception, allowing KeyboardInterrupt and SystemExit to propagate.
  • Logs the full traceback.
  • Chains the original error with raise ... from e.

3. Preserve _bots.py startup failures

If AugurManager() failed, _bots.py continued with an uninitialized dbm, masking the original error with NameError.

The original KeyError or SQLAlchemyError is now logged and re-raised.

4. Correct cache bookkeeping

caching_wrapper() recorded every requested repository, including repositories already cached. This created duplicate bookkeeping rows.

Query parameters and uncached repository IDs now use separate variables, and bookkeeping records only repositories fetched by the current operation.

Result

  • Empty repository selections no longer cause SQL or callback errors.
  • Database failures retain their original cause and traceback.
  • Startup failures are no longer masked.
  • Cache bookkeeping no longer adds duplicates for already-cached repositories.

Validation

  • Pre-commit hooks and Black formatting pass.
  • Changed files compile successfully.
  • Independent review found no remaining correctness defects.

Generative AI disclosure

Please select one option:

  • This contribution was NOT assisted or created by Generative AI tools.
  • This contribution was assisted or created by Generative AI tools.

If AI tools were used, please provide details below:
- What tools were used? Claude Opus 5, GPT 5.6 - sol
- How were these tools used? Draft, multiple iterations, review.
- Did you review these outputs before submitting this PR? Yes.

Callbacks fire on initial page load with repo-choices still [], and
psycopg2 renders an empty sequence as "()", so "WHERE repo_id in ()"
errored on every fresh session.

get_uncached returns [] early. retrieve_from_cache sends a NULL sentinel
rather than returning early, since a bare DataFrame has no columns and
twelve call sites preprocess on columns before testing df.empty.
get_default_repo_with_data guards separately -- it indexes repo_ids[0].
run_query's bare except also caught KeyboardInterrupt/SystemExit and
dropped the cause, so a timeout, a bad column and a dropped connection
were indistinguishable. _bots.py logged the KeyError then fell through to
an unbound dbm, raising NameError instead.

caching_wrapper recorded bookkeeping for the full repolist rather than the
repos it actually cached, adding a duplicate row per already-resident repo
to the table the poll loops query twice a second. The stale name came from
rebinding uncached_repos to the query vars; those are now separate.
@EngCaioFonseca EngCaioFonseca self-assigned this Sep 4, 2026
@EngCaioFonseca EngCaioFonseca added the bug Something isn't working label Sep 4, 2026
@EngCaioFonseca EngCaioFonseca moved this from Backlog to Testing | Waiting on PR response | Blocked in Aspen Project Board Sep 4, 2026
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Testing | Waiting on PR response | Blocked

Development

Successfully merging this pull request may close these issues.

Home page metric callbacks create a new engine per call and interpolate the repo lists into Sql labels

1 participant