Skip to content

fix: GC endpoint: satellites/{satellite}/images returns 500, resolves #366#367

Open
NucleoFusion wants to merge 1 commit intocontainer-registry:mainfrom
NucleoFusion:fix/#366
Open

fix: GC endpoint: satellites/{satellite}/images returns 500, resolves #366#367
NucleoFusion wants to merge 1 commit intocontainer-registry:mainfrom
NucleoFusion:fix/#366

Conversation

@NucleoFusion
Copy link
Copy Markdown

@NucleoFusion NucleoFusion commented Apr 8, 2026

Description

Changes sql query from:

SELECT a.id, a.reference, a.size_bytes, a.created_at
FROM artifacts a
WHERE a.id = ANY(
    (SELECT artifact_ids FROM satellite_status
     WHERE satellite_id = $1
     ORDER BY created_at DESC LIMIT 1)
)
ORDER BY a.reference;

to
``sql
SELECT a.id, a.reference, a.size_bytes, a.created_at
FROM artifacts a
WHERE a.id IN (
SELECT unnest(artifact_ids) FROM (
SELECT artifact_ids FROM satellite_status
WHERE satellite_id = $1
ORDER BY created_at DESC LIMIT 1
) latest
)
ORDER BY a.reference;


## Additional context

<!-- Add any other context about the PR here. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Refactor**
  * Optimized the database query for retrieving latest satellite artifacts to improve query reliability and consistency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: NucleoFusion <lakshit.singh.mail@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6fef35ef-9a37-41e1-a60c-56e58334e9a6

📥 Commits

Reviewing files that changed from the base of the PR and between 97ee470 and f9998a6.

📒 Files selected for processing (2)
  • ground-control/internal/database/satellite_status.sql.go
  • ground-control/sql/queries/satellite_status.sql

📝 Walkthrough

Walkthrough

The PR corrects the GetLatestArtifacts SQL query to fix a PostgreSQL syntax error. The query was using = ANY() with a subquery returning an array, which PostgreSQL cannot process directly. The fix replaces this pattern with explicit unnest() and IN to properly expand array elements into scalar values for filtering.

Changes

Cohort / File(s) Summary
GetLatestArtifacts Query Fix
ground-control/sql/queries/satellite_status.sql, ground-control/internal/database/satellite_status.sql.go
Corrected artifact filtering logic by replacing a.id = ANY((SELECT artifact_ids ...)) with a.id IN (SELECT unnest(artifact_ids) FROM (...) latest) to properly expand the array into individual rows for membership testing. Resolves PostgreSQL operator incompatibility with direct array subquery results.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the fix: a 500 error in the GC endpoint /satellites/{satellite}/images and references the issue number.
Description check ✅ Passed The description follows the template with 'Fixes: #366' and 'Description' sections; SQL changes are clearly documented with before/after code.
Linked Issues check ✅ Passed The code changes directly address issue #366 by replacing the problematic = ANY(subquery) with IN (SELECT unnest(...)) to properly handle array expansion.
Out of Scope Changes check ✅ Passed Changes are limited to the SQL query in GetLatestArtifacts, directly addressing the stated objective of fixing the 500 error in the endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the golang label Apr 8, 2026
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Ground Control endpoint /satellites/{satellite}/images returns 500

1 participant