-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Make ungrounded types have a default name when sending to the frontend #5133
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR fixes a Pydantic serialization error in the Knowledge Graph (KG) admin functionality. The issue occurred when compiling entity statistics for the frontend - ungrounded entities in the database can have null grounded_source_name
values, but the SourceStatistics
Pydantic model expects a non-null string for its source_name
field, causing serialization failures.
The fix involves three coordinated changes:
-
Making the constant public: The
_UNGROUNDED_SOURCE_NAME
constant inentity_type.py
is renamed toUNGROUNDED_SOURCE_NAME
to make it publicly accessible across modules. -
Adding fallback logic: In
entities.py
, theget_entity_stats_by_grounded_source_name()
function now uses the null coalescing operator (or
) to provide the default "Ungrounded" name whengrounded_source_name
is null. -
Improving variable naming: The API endpoint code in
kg/api.py
uses more descriptive variable names (source_name
instead ofkey
) for better code clarity.
This approach maintains consistency with existing patterns in the codebase - the same UNGROUNDED_SOURCE_NAME
constant is already used in the get_configured_entity_types()
function. The fix ensures that entity statistics can be properly compiled and serialized for the frontend while preserving the semantic meaning that some entities are "ungrounded" (not associated with a specific source).
Confidence score: 5/5
- This is a safe, well-targeted fix that addresses a specific serialization bug without breaking existing functionality.
- The solution follows established patterns in the codebase and maintains consistency across the KG system.
- No files need additional attention - the changes are straightforward and the logic is sound.
3 files reviewed, 1 comment
backend/onyx/db/entities.py
Outdated
# `row.grounded_source_name`` is NULLABLE in the database schema. | ||
# Thus, for all "ungrounded" entity-types, we use a default name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Extra backtick in the comment - should be 'row.grounded_source_name' instead of 'row.grounded_source_name``'
# `row.grounded_source_name`` is NULLABLE in the database schema. | |
# Thus, for all "ungrounded" entity-types, we use a default name. | |
# `row.grounded_source_name` is NULLABLE in the database schema. | |
# Thus, for all "ungrounded" entity-types, we use a default name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic analysis
1 issue found across 3 files • Review in cubic
React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ontend (#5133) * Update names in map-comprehension * Make default name for ungrounded types public * Return the default name for ungrounded entity-types * Update backend/onyx/db/entities.py Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…ontend (onyx-dot-app#5133) * Update names in map-comprehension * Make default name for ungrounded types public * Return the default name for ungrounded entity-types * Update backend/onyx/db/entities.py Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Description
When compiling stats on entities, ungrounded entities were throwing errors because the logic expected that
grounded_source_name
to be non-null. However, it is possible forgrounded_source_name
to be null (hence the "ungrounded source"), which caused an error in pydantic serialization.This PR fixes that issue by assigning a default name to all ungrounded entities when compiling the stats for the frontend.
Addresses: https://linear.app/danswer/issue/DAN-2255/fix-kg-admin-deserialization-serialization-issue.
How Has This Been Tested?
Untested.
Summary by cubic
Fixed errors when compiling entity stats by assigning a default name to ungrounded types before sending data to the frontend, ensuring proper serialization.