Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(property-defs-rs API): misc. query and response gen improvements #29332

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eli-r-ph
Copy link
Contributor

Problem

After landing the spike PR for the new property-defs-rs REST API, I've been testing the API in local dev with a mix of real (hand-clicked like grandma used to make!) and synthetic events. this PR represents the first round of fixes and improvements that shook out.

Changes

  • Fix some bugs in the query generation logic
  • Fix row deserialization and response generation

Of note: I did some research and apparently dynamically generated queries in sqlx have a rough spot around deserializing rows into nested structs, even when the struct fields support decoding, so I added an intermediate step. If I'm missing something, let me know 👍 (cc @oliverb123 )

Does this work well for both Cloud and self-hosted?

N/A

How did you test this code?

Locally and in CI

@eli-r-ph eli-r-ph self-assigned this Feb 28, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR improves the property-defs-rs API with fixes to query generation and response handling.

  • Changed JOIN type from INNER to LEFT JOIN for user tables, ensuring property definitions with null user references are still returned
  • Added column aliases with prefixes (ub_ for updated_by, vb_ for verified_by) to properly distinguish between user table instances
  • Removed unused columns from constants and simplified table column definitions
  • Improved URI handling with better fallbacks for scheme and authority in pagination URL generation
  • Implemented two-step row deserialization approach to handle the limitations of sqlx with dynamically generated queries

3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +395 to +397
let raw = row.ub_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This unwrap() could panic if ub_hedgehog_config is None. Since you're already checking with is_some(), consider using unwrap_or_default() or just pass the Option directly to serde_json::from_str.

Suggested change
let raw = row.ub_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
}
if let Some(raw) = &row.ub_hedgehog_config {
hcfg = serde_json::from_str(raw).unwrap_or(None);
}

Comment on lines +417 to +419
let raw = row.vb_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same unwrap() issue here as above - could panic if vb_hedgehog_config is None.

Suggested change
let raw = row.vb_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
}
if let Some(raw) = &row.vb_hedgehog_config {
hcfg = serde_json::from_str(raw).unwrap_or(None);
}

let mut hcfg: Option<HedgehogConfig> = None;
if row.ub_hedgehog_config.is_some() {
let raw = row.ub_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: serde_json::from_str returns a Result, not an Option. The unwrap_or(None) will only be used if there's a parsing error, not if the JSON is null or empty.

let mut hcfg: Option<HedgehogConfig> = None;
if row.vb_hedgehog_config.is_some() {
let raw = row.vb_hedgehog_config.unwrap();
hcfg = serde_json::from_str(&raw).unwrap_or(None);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same issue with serde_json::from_str here - it returns a Result, not an Option.

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.

1 participant