Skip to content
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

sql(params_inline=True) doesn't include filter values from subqueries #1800

Open
Abdeldjalil-H opened this issue Dec 4, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Abdeldjalil-H
Copy link
Contributor

Describe the bug
When using .sql(params_inline=True) on a query that contains filters with subqueries, the filter values from the subqueries are not included in the generated raw SQL.

Current Behavior

When calling .sql(params_inline=True) on a query with subquery filters, the filter values from the subquery are not included in the final SQL string.

Expected Behavior

The filter values from subqueries should be included in the generated SQL when using params_inline=True.

Minimal Reproducible Example

from tortoise import Model, fields, Tortoise, run_async
from tortoise.expressions import Subquery


class OtherModel(Model):
    id = fields.IntField(pk=True)
    field = fields.CharField(max_length=255)

    class Meta:
        table = "other_model"


class MyModel(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255)

    class Meta:
        table = "my_model"


async def main():
    config = {
        "connections": {"default": "sqlite://:memory:"},
        "apps": {
            "models": {
                "models": ["__main__"],
                "default_connection": "default",
            }
        },
    }
    await Tortoise.init(config=config)
    await Tortoise.generate_schemas()

    # The query
    query = MyModel.filter(id__in=Subquery(OtherModel.filter(field="test_value").values_list("id")))

    # Generate SQL with inline params
    sql = query.sql(params_inline=True)
    print(sql)  # The value "test_value" is not included in the output
    await Tortoise.close_connections()


if __name__ == "__main__":
    run_async(main())

Additional Context

  • Tortoise-ORM version: 0.22.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants