Skip to content

Conversation

@PRAteek-singHWY
Copy link
Contributor

Fix GAP analysis job result handling for empty-but-valid results

Description

This PR fixes an issue where successful GAP analysis background jobs could incorrectly return a 500 error when the computed result was empty.

The RQ worker correctly completes the job and stores a result in the cache, but the web layer previously treated empty results as invalid and raised an internal error.

Problem

When fetching GAP analysis results via /rest/v1/ma_job_results, the web layer checked the result using a truthiness check:

if ga.get("result"):
If the GAP analysis produced zero paths, the stored payload looked like:
{"result": {}}

Since an empty dictionary evaluates to False, the API incorrectly entered the error branch and raised:

Finished job does not have a result object, this is a bug!

This occurred even though:

  • The RQ worker completed successfully
  • The result was valid and intentionally empty
  • The data was correctly stored in the database cache

Root Cause

The API was conflating:

  • “result does not exist” with
  • “result exists but is empty”

An empty GAP analysis is a valid outcome (e.g. no paths found between two standards).

Solution

The API now checks for presence of the result key, not its truthiness:

The API now checks for presence of the result key, not its truthiness:

if "result" in ga:

This allows empty-but-valid results to be returned to the frontend instead of triggering a 500 error.

The same logic is applied consistently across:

  • /rest/v1/map_analysis
  • /rest/v1/map_analysis_weak_links
  • /rest/v1/ma_job_results

Behavior After This Change

  • ✅ Successful GAP jobs always return a response
  • ✅ Empty GAP results are returned as { "result": {} }
  • ❌ Genuine failures (missing cache, failed jobs, invalid payloads) still return errors
  • ❌ No worker-side behavior is altered

Related Issue

Fixes #583 – Running a GAP background job does not return a result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running a GAP background job does not return a result

1 participant