FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✨ Increase `number_of_types` to 5 to support longer select queries by GiorgioPorgio · Pull Request #1333 · fastapi/sqlmodel · GitHub

Repository navigation

✨ Increase number_of_types to 5 to support longer select queries - #1333

Open
GiorgioPorgio wants to merge 1 commit into
fastapi:mainfrom
GiorgioPorgio:add-typing-for-5-args-in-select
Open

GiorgioPorgio wants to merge 1 commit into
fastapi:mainfrom
GiorgioPorgio:add-typing-for-5-args-in-select

Conversation

GiorgioPorgio commented Mar 27, 2025 •
edited
Loading

Copy link
Copy Markdown

I am trying to write a select statement that selects 5 different SQLModel children. However I get a type error as the overloads for select are limited to 4.

Increasing to 6+ causes mypy to hang, so I chose 5 :)

Resolves #271 (comment)

Thank you very much for your time and working on OSS!

@@ -107,6 +107,24 @@
_T3 = TypeVar("_T3")


Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Everything in this file is autogenerated by running the script (*_*)

svlandeg changed the title increase typing to 5 args in select ✨ Increase number_of_types to 5 to support longer select queries Apr 4, 2025
svlandeg added the feature New feature or request label Apr 4, 2025

YuriiMotov commented Aug 14, 2025 •
edited
Loading

Copy link
Copy Markdown
Member

Just as an idea:
what if we introduce a rule that all _TScalar_XX should go before any of _TCCA[_TXX]?
This way we only need to add 7 overloads for the 5 parameters, 8 overloads for 6 parameters, etc..

See example for 5 parameters in the details:

Details
@overload
def select(  # type: ignore
    __ent0: _TCCA[_T0],
    __ent1: _TCCA[_T1],
    __ent2: _TCCA[_T2],
    __ent3: _TCCA[_T3],
    __ent4: _TCCA[_T4],
) -> Select[Tuple[_T0, _T1, _T2, _T3, _T4]]: ...


@overload
def select(  # type: ignore
    entity_0: _TScalar_0,
    __ent1: _TCCA[_T1],
    __ent2: _TCCA[_T2],
    __ent3: _TCCA[_T3],
    __ent4: _TCCA[_T4],
) -> Select[Tuple[_TScalar_0, _T1, _T2, _T3, _T4]]: ...


@overload
def select(  # type: ignore
    entity_0: _TScalar_0,
    entity_1: _TScalar_1,
    __ent2: _TCCA[_T2],
    __ent3: _TCCA[_T3],
    __ent4: _TCCA[_T4],
) -> Select[Tuple[_TScalar_0, _TScalar_1, _T2, _T3, _T4]]: ...


@overload
def select(  # type: ignore
    entity_0: _TScalar_0,
    entity_1: _TScalar_1,
    entity_2: _TScalar_2,
    __ent3: _TCCA[_T3],
    __ent4: _TCCA[_T4],
) -> Select[Tuple[_TScalar_0, _TScalar_1, _TScalar_2, _T3, _T4]]: ...


@overload
def select(  # type: ignore
    entity_0: _TScalar_0,
    entity_1: _TScalar_1,
    entity_2: _TScalar_2,
    entity_3: _TScalar_3,
    __ent4: _TCCA[_T4],
) -> Select[Tuple[_TScalar_0, _TScalar_1, _TScalar_2, _TScalar_3, _T4]]: ...


@overload
def select(  # type: ignore
    entity_0: _TScalar_0,
    entity_1: _TScalar_1,
    entity_2: _TScalar_2,
    entity_3: _TScalar_3,
    entity_4: _TScalar_4,
) -> Select[Tuple[_TScalar_0, _TScalar_1, _TScalar_2, _TScalar_3, _TScalar_4]]: ...


@overload
@deprecated(
    """
    This version of `select` function is deprecated.
    You should order parameters so that all `_TScalar_XX` parameters would go before any
    of `_TCCA[_TXX]` parameter.

    Read more: [link to the documentation]
    """
)
def select(  # type: ignore
    __ent0: _TCCA[_T0],
    param_1: Any,
    param_2: Any,
    param_3: Any,
    param_4: Any,
) -> Select[Tuple[_T0, Any, Any, Any, Any]]: ...

Last overload is to catch the wrong parameters order and show the deprecation warning with clear message and link to the docs.

We can leave overloads for 1-4 parameters as it is for backward compatibility, or optionally mark overloads that don't follow this rule as deprecated.

dtip commented Oct 29, 2025

Copy link
Copy Markdown

Increasing the limit from 4 to 5 means this problem will happen again when someone has a select with 6 inputs. I'm not familiar with the code at all, but is there some way to accept an arbitrarily large number of inputs? Or increase the limit to something absurd like 50?

GiorgioPorgio commented Nov 17, 2025 •
edited
Loading

Copy link
Copy Markdown
Author

is there some way to accept an arbitrarily large number of inputs? Or increase the limit to something absurd like 50?

Unfortunately no. Because of limitations of Python typing regarding order of generic types, you have to explicitly specify every possible combination, leading to a factorial explosion.

@YuriiMotov 's solution could work perhaps, have not tested it and Python is not my main laguage. I think both solutions would help the community.

I acknowledge the current PR is more of a quick win but a safe change that would improve DX.

isbldr commented Mar 4, 2026

Copy link
Copy Markdown

I'm running into this one as I have query with 7 columns and the suggestion from @YuriiMotov would indeed help me as it's pretty trivial to order the columns.

Copy link
Copy Markdown

Note that SQLAlchemy's select supports 10 arguments. At least match that.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No overload variant of "select" matches argument types

7 participants


Back | FazBrowse Home | New Git URL