Skip to content

Add full custom query for observations#39

Merged
dmitrkozlovsk merged 1 commit intomainfrom
feature/full_custom_query
Oct 18, 2025
Merged

Add full custom query for observations#39
dmitrkozlovsk merged 1 commit intomainfrom
feature/full_custom_query

Conversation

@dmitrkozlovsk
Copy link
Owner

This commit introduces the ability to run experiment observations using a fully custom SQL query, bypassing the standard template-based query generation. This provides greater flexibility for complex or non-standard analyses.
closed #29

@dmitrkozlovsk dmitrkozlovsk merged commit c19db3f into main Oct 18, 2025
2 checks passed
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 346 to +351
"Supports JOINs, CTEs, subqueries, and complex aggregations. "
"Modifying operations (INSERT, UPDATE, DELETE) are not allowed.",
)
full_custom_query = st.text_area(
"Full Custom Query", value="", key="full_custom_query_input_key"
)

Choose a reason for hiding this comment

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

P1 Badge Preserve full custom query when editing observations

The new form field for full_custom_query is always initialised with an empty string (st.text_area(..., value="", ...)) while the submission code later passes that value to the update handler. When an observation that already has a custom query is opened for editing, the text area shows up blank and submitting the form (even without touching that field) overwrites the existing SQL with an empty string. After any edit the observation silently reverts to template-based rendering. Pre-populate the field with the existing value, similar to custom_test_ids_query, so that updates don’t erase user-provided custom queries.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +349 to +351
full_custom_query = st.text_area(
"Full Custom Query", value="", key="full_custom_query_input_key"
)

Choose a reason for hiding this comment

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

P1 Badge Preserve full_custom_query when updating observations

The new text area for full_custom_query is always initialized with an empty string. When a user edits an existing observation the saved query is not shown, and asdict later sends the empty value back to update_observation, wiping the stored SQL even if the user never touched the field. This causes data loss whenever any other attribute is changed. Prefilling the widget with predefined.full_custom_query (defaulting to None) would keep existing queries intact.

Useful? React with 👍 / 👎.

Comment on lines +349 to +351
full_custom_query = st.text_area(
"Full Custom Query", value="", key="full_custom_query_input_key"
)

Choose a reason for hiding this comment

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

P0 Badge Full custom query lacks read-only validation before execution

full_custom_query is taken straight from the Streamlit form and executed by the runner, but unlike custom_test_ids_query it is never passed through ValidationUtils.validate_sql_query. A user can therefore submit mutating statements (INSERT, DROP, etc.) that will execute under application credentials. Because other SQL fields are explicitly validated to be read-only, this omission is a security regression. The field should be validated or otherwise constrained before rendering/execution.

Useful? React with 👍 / 👎.

Comment on lines 176 to +184
comment="Custom query to calculate the test_ids for the experiment. "
"The query will be used in jinja template instead of the default query",
)
full_custom_query = Column(
Text,
nullable=True,
comment="Full custom query to calculate metrics. "
"If provided, this query will be used instead of the template-based query.",
)

Choose a reason for hiding this comment

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

P1 Badge Add migration for Observation.full_custom_query column

The ORM model now defines a full_custom_query column, but no schema migration accompanies the change. Existing installations will have an observations table without this column, so attempts to create or update an observation that includes full_custom_query will fail with database errors (e.g. “no such column: observations.full_custom_query”). A migration or other schema update is required to keep the database consistent with the model.

Useful? React with 👍 / 👎.

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.

Add options to use fully custom script / template for observation

1 participant