Skip to content

Let favorite queries use Jinja2 templates - #2085

Open
rolandwalker wants to merge 1 commit into
mainfrom
RW/jinja2-favorite-queries-optional-parameters
Open

Let favorite queries use Jinja2 templates#2085
rolandwalker wants to merge 1 commit into
mainfrom
RW/jinja2-favorite-queries-optional-parameters

Conversation

@rolandwalker

@rolandwalker rolandwalker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

Let favorite queries use Jinja2 templates, allowing optional arguments and control blocks in favorite queries.

Include completions for Jinja2 key names. Supporting the completions is quite a bit more code than the core functionality! Completions also can only be offered if the key name is referred to explicitly in the template (not merely iterated over, which is technically possible).

Extensively update the config file and internal helpdoc with examples and notes.

It seems arbitrary to choose whether Jinja2 templates are processed before or after the legacy positional arguments are substituted. I chose Jinja2 before positional. The agent hacked together a UUID-based solution for this, which may not be pretty.

There is one regression: whereas a positional argument could previously freely begin with the dash character, that can now be ambiguous with the --key=value syntax. The solution is to disambiguate by putting such positional values after a --:

/f query --key=value -- --ambiguous-positional-value--

This should be rare enough that the regression is worth the new feature.

This adds a Jinja2 direct dependency to the project. It was already a transitive dependency via altair if mycli was installed with dataframe support.

Fixes #1871

Edit: it looks like there is a bug here in that we determine that a key is unused unless it is referred to explicitly. That logic should apply to completions only. Will fix, but it is a real edge case, and this PR is still reviewable. Fixed.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Aug 3, 2026
@rolandwalker
rolandwalker force-pushed the RW/jinja2-favorite-queries-optional-parameters branch from 949c9be to 7e5d868 Compare August 3, 2026 11:04
allowing optional arguments and control blocks in favorite queries.

Include completions for Jinja2 key names.  Supporting the completions is
quite a bit more code than the core functionality!  Completions also
can only be offered if the key name is referred to explicitly in the
template (not merely iterated over, which is technically possible).

Extensively update the config file and internal helpdoc with examples
and notes.

It seems arbitrary to choose whether Jinja2 templates are processed
before or after the legacy positional arguments are substituted.  I
chose Jinja2 before positional.  The agent hacked together a UUID-based
solution for this, which may not be pretty.

There is one regression: whereas a positional argument could previously
freely begin with the dash character, that can now be ambiguous with the
--key=value syntax.  The solution is to disambiguate by putting such
positional values after a "--":

    /f query --key=value -- --ambiguous-positional-value--

This should be rare enough that the regression is worth the new feature.

This adds a Jinja2 direct dependency to the project.  It was already a
transitive dependency via altair if mycli was installed with dataframe
support.
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.

How about Favorite queries Positional Parameters add Default values support

1 participant