tortoise / pypika-tortoise Goto Github PK
View Code? Open in Web Editor NEWForked from pypika and streamline just for tortoise-orm
License: Apache License 2.0
Forked from pypika and streamline just for tortoise-orm
License: Apache License 2.0
Say you have a query like this:
await Student.all().update(school=school2)
this will produce
UPDATE "student" SET "school_id"=?
It will also work perfectly fine if we filter on the same table, like so:
Student.filter(name='test').update(school=school2).as_query()
which produces
UPDATE "student" SET "school_id"=? WHERE "name"='test'
However, if we join a table to filter on for the update, it gets the order wrong. So this
Student.filter(school__id=school2.id).update(name="test").as_query()
produces
UPDATE "student"
LEFT OUTER JOIN "school" "student__school" ON "student__school"."id"="student"."school_id"
SET "name"=?
WHERE "student__school"."id"=2048
The correct sql statement for this would be
UPDATE "student"
SET "name"=?
FROM "student"
LEFT OUTER JOIN "school" "student__school" ON "student__school"."id"="student"."school_id"
WHERE "student__school"."id"=2048
I did some digging, and the querybuilder seems to be the issue here, hence me opening an issue on this repo. This also relates to this issue on the main repo tortoise/tortoise-orm#1081
The original pypika
has the bug kayak/pypika#560 which was fixed in kayak/pypika#576. pypika-tortoise
has the same bug.
import asyncio
from tortoise import fields, Tortoise, Model
from enum import Enum
class MyModel(Model):
name = fields.TextField()
class MyEnum(str, Enum):
A = "a"
async def do():
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
qs = MyModel.filter(name=MyEnum.A)
qs._make_query()
print(qs.query)
# expected SELECT "id","name" FROM "mymodel" WHERE "name"='a'
# actual SELECT "id","name" FROM "mymodel" WHERE "name"=a
asyncio.run(do())
When pypika
and pypika-tortoise
are both installed, both are installed within the same site-packages directory (see #5). This causes an ImportError
, because dialects/__init__.py
is imported by upstream pypika
's __init__.py
, instead of its own dialects.py
:
File "/myproject/.venv/lib/python3.10/site-packages/tortoise/__init__.py", line 11, <module>
from pypika import Table
File "/myproject/.venv/lib/python3.10/site-packages/pypika/__init__.py", line 34, <module>
from pypika.dialects import (
dialects: <module 'pypika.dialects' from '/myproject/.venv/lib/python3.10/site-packages/pypika/dialects/__init__.py'>
ImportError:
cannot import name 'ClickHouseQuery' from 'pypika.dialects' (/myproject/.venv/lib/python3.10/site-packages/pypika/dialects/__init__.py)
Please rename this package.
And if you've watched "the Fly", you'll know the disastrous consequences of merging two species π .
Since this library is an incompatible fork of pypika it would be good if the package directory, which is currently called pypika, would be renamed. Otherwise the original pypika and tortoise-orm conflict when installed into the same environment. Even better would be a namespace package in which this pypika fork lives under the tortoise namespace, since β realistically β it wonβt be used by anyone else anyway.
Hello.
Can you please update release tag? There are already many new commits in main.
And in TortoiseORM
use it's package version, not git version like pypika-tortoise = { git = "https://github.com/tortoise/pypika-tortoise.git", branch = "main" }
(in pyproject.toml
), because it's inconvenient to pull from git. For example, in corporate use that can be a problem.
Realize tortoise-orm
depends on this repo instead of pypika just now ! Even though it gives much more freedom for tortoise-orm
, but much extra pressure for author. It seems little behind of official one.
Should I pull a same requests here ? So that remove the patch from tortoise-orm.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.