Skip to content

Use default CTE name when name is None - #150

Open
terencehonles wants to merge 1 commit into
dimagi:mainfrom
terencehonles:use-default-cte-name-on-None
Open

terencehonles wants to merge 1 commit into
dimagi:mainfrom
terencehonles:use-default-cte-name-on-None

Conversation

@terencehonles

@terencehonles terencehonles commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This change moves the default CTE name ("cte") into the initializer. In addition to None, this also handles an empty CTE name.

Pulled out of #142

The rationale for this change mainly revolves around functions who wrap CTE. This is particularly focused on wrappers who use another name for the keyword argument and/or use Python typing. In either case you have to either specify the default CTE name or special case the call so you can omit the CTE name.

The following code would be simplified with this change:

# "cte" is copied in the signature to put *something* for a name
def wrapper[M: Model](model: M, ..., *, cte_name: str = "cte", **wrapper_kwargs: Any) -> QuerySet[M]:
    ...
    cte = CTE(..., name=cte_name)

# "cte" is copied in the call site to put *something* for a name
def wrapper[M: Model](model: M, ..., *, cte_name: str | None = None, **wrapper_kwargs: Any) -> QuerySet[M]:
    ...
    cte = CTE(..., name=cte_name or "cte")

# name is optionally provided to `CTE`
def wrapper[M: Model](model: M, ..., *, cte_name: str | None = None, **wrapper_kwargs: Any) -> QuerySet[M]:
    ...
    cte = CTE(..., **({"name": cte_name} if cte_name else {}))

could instead be:

def wrapper[M: Model](model: M, ..., *, cte_name: str | None = None, **wrapper_kwargs: Any) -> QuerySet[M]:
    ...
    cte = CTE(..., name=cte_name)

In the future, it seems like the CTE names could be auto generated if not provided, and using None as a sentinel is easier to detect than comparing to the default name "cte" or any other names that wrappers have provided as their own defaults (they don't have to use "cte").

@terencehonles
terencehonles force-pushed the use-default-cte-name-on-None branch from b8ff8bd to f5e90ac Compare October 9, 2026 12:41
@terencehonles terencehonles changed the title [Rebase after #142]: Use default CTE name when name is None Use default CTE name when name is None Oct 9, 2026
@terencehonles
terencehonles marked this pull request as ready for review October 9, 2026 13:52

@millerdev millerdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this change is worth it. If a wrapper cannot pass **kwargs through from the caller, possibly including a custom name, it can supply its own default CTE name. The default CTE name is arbitrary and has no special meaning.

This branch has not been deployed

No deployments
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.

2 participants