Skip to content

fix: construct db_icon from datasource_name when missing in API response#38

Merged
wicky-zipstack merged 2 commits intomainfrom
fix/connection-icon-broken
Apr 8, 2026
Merged

fix: construct db_icon from datasource_name when missing in API response#38
wicky-zipstack merged 2 commits intomainfrom
fix/connection-icon-broken

Conversation

@wicky-zipstack
Copy link
Copy Markdown
Contributor

@wicky-zipstack wicky-zipstack commented Apr 2, 2026

What

  • Construct db_icon URL from datasource_name when missing in the create/update connection API response

Why

  • After the recent optimization to use API response data directly instead of re-fetching the connection list, the connection dropdown shows broken image icons
  • The create/update connection API response does not include the db_icon field
  • The dropdown renders <img src={undefined}> resulting in a broken image placeholder

How

  • In NewProject.jsx and NewEnv.jsx, when handling the optimistic update with updatedConnection data, check if db_icon is missing
  • If missing, construct the URL from datasource_name using the static pattern: https://storage.googleapis.com/visitran-static/adapter/{datasource_name}.png
  • Handles the postgrespostgresql naming mismatch

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No. This only adds a fallback when db_icon is missing. If db_icon is already present in the response, the existing value is used unchanged. No impact on connections fetched from the list API (which already include db_icon).

Database Migrations

  • None

Env Config

  • None

Relevant Docs

  • N/A

Related Issues or PRs

Dependencies Versions

  • None

Notes on Testing

  • Create a new connection from the Create Project modal — icon should appear correctly in dropdown
  • Create a new connection from the Environment modal — icon should appear correctly
  • Test with different DB types (Postgres, Snowflake, BigQuery, DuckDB)
  • Verify existing connections (fetched from list API) still show icons correctly

Screenshots

N/A

Checklist

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 2, 2026

Greptile Summary

Fixes a broken icon bug introduced by a previous optimization that switched from re-fetching the connection list to using the create/update API response directly. Since those endpoints omitted db_icon, the frontend rendered broken image placeholders (<img src={undefined}>). The fix adds db_icon to both create_connection and update_connection responses in ConnectionContext, using the existing import_file(...).ICON pattern already present in 5+ other backend locations (connection_session.py, env_session.py, base_context.py, views.py). This is a correct root-cause fix at the API layer rather than a frontend workaround.

  • Added db_icon field to create_connection response (line 139) and update_connection response (line 183) in connection.py
  • Uses import_file(f"visitran.adapters.{datasource_name}").ICON — fully consistent with the pattern used across the rest of the codebase
  • The postgres → postgresql naming mismatch is handled naturally by the adapter's own ICON constant (postgresql.png), requiring no manual string mapping in this code
  • No new error-handling risk: by the time import_file is called, the adapter has already been validated implicitly by the earlier test_connection_data and get_connection_data calls in the same function
  • Addresses the previous review concern about duplicated frontend fallback logic — the fix lives entirely in the backend, so no frontend duplication is necessary

Confidence Score: 5/5

Safe to merge — the fix correctly adds a missing field to the API response using a well-established codebase pattern.

Single-file change applying a pattern already used in 5+ other locations. All adapter init.py files define ICON; the datasource name is implicitly validated earlier in the call chain by test_connection_data and get_connection_data; no P0 or P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
backend/backend/application/context/connection.py Adds db_icon to create/update connection API responses using the existing import_file pattern; consistent with all other endpoints in the codebase

Sequence Diagram

sequenceDiagram
    participant FE as Frontend
    participant API as Connection API
    participant CTX as ConnectionContext
    participant DB as Database
    participant ADP as Adapter Module

    FE->>API: POST /connections (create)
    API->>CTX: create_connection(connection_details)
    CTX->>DB: test_connection_data(datasource, data)
    CTX->>DB: connection_session.create_connection()
    DB-->>CTX: connection_model
    CTX->>ADP: import_file("visitran.adapters.{datasource_name}").ICON
    ADP-->>CTX: db_icon URL
    CTX-->>API: {id, name, datasource_name, db_icon, ...}
    API-->>FE: 200 OK with db_icon included

    FE->>API: PUT /connections/{id} (update)
    API->>CTX: update_connection(id, connection_details)
    CTX->>DB: connection_session.update_connection()
    DB-->>CTX: connection_model
    CTX->>ADP: import_file("visitran.adapters.{datasource_name}").ICON
    ADP-->>CTX: db_icon URL
    CTX-->>API: {id, name, datasource_name, db_icon, ...}
    API-->>FE: 200 OK with db_icon included
Loading

Greploops — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.
Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

Reviews (3): Last reviewed commit: "fix: include db_icon in connection creat..." | Re-trigger Greptile

The create/update connection API response doesn't include db_icon,
causing broken image icons in the connection dropdown after creating
a new connection. Now constructs the icon URL from datasource_name
when db_icon is missing.
Move db_icon resolution to the backend (connection.py) so create and
update endpoints return db_icon consistently, matching the list endpoint.
This removes the need for frontend icon-fallback logic.
Copy link
Copy Markdown
Contributor

@tahierhussain tahierhussain left a comment

Choose a reason for hiding this comment

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

LGTM

@wicky-zipstack wicky-zipstack merged commit a7af325 into main Apr 8, 2026
3 of 4 checks passed
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.

3 participants