Skip to content

feat(crons): Add CronMonitorDataSourceHandler #97548

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wedamija
Copy link
Member

@wedamija wedamija commented Aug 8, 2025

Adding a new DataSourceHandler so that we can treat cron Monitor rows as a DataSource

Adding a new `DataSourceHandler` so that we can treat cron `Monitor` rows as a `DataSource`
@wedamija wedamija requested a review from a team August 8, 2025 23:59
@wedamija wedamija requested a review from a team as a code owner August 8, 2025 23:59
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 8, 2025
Comment on lines +808 to +820
for ds in data_sources:
try:
monitor_ids.append(int(ds.source_id))
except ValueError:
logger.exception(
"Invalid DataSource.source_id fetching Monitor",
extra={"id": ds.id, "source_id": ds.source_id},
)

qs_lookup = {
str(monitor.id): monitor for monitor in Monitor.objects.filter(id__in=monitor_ids)
}
return {ds.id: qs_lookup.get(ds.source_id) for ds in data_sources}
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential bug: The `DataSourceSerializer` incorrectly maps data sources when some are invalid, leading to data corruption where users see data from the wrong monitor.
  • Description: When bulk_get_query_object is called with a list of data sources where some have invalid source_ids, it returns None for the invalid ones. The consuming DataSourceSerializer filters out these None values before zipping the serialized results with the original list of data sources. This causes a misalignment in the zip(ds_query_objs, serialized) operation, leading to serialized data from one monitor being incorrectly associated with a different data source. This results in data corruption in the API response, where users might see information belonging to another monitor.
  • Suggested fix: Modify the DataSourceSerializer to handle None values without causing list misalignment. Instead of filtering Nones before serialization, iterate through the original list, conditionally serialize items, and maintain a list of the same length as the original to ensure the zip operation pairs items correctly.
    severity: 0.8, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link

codecov bot commented Aug 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #97548      +/-   ##
==========================================
- Coverage   80.62%   80.62%   -0.01%     
==========================================
  Files        8560     8560              
  Lines      376889   376917      +28     
  Branches    24538    24538              
==========================================
+ Hits       303870   303889      +19     
- Misses      72649    72658       +9     
  Partials      370      370              

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant