-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Feature: expose timezone
and use_tz
params in RegisterTortoise class
#1632
Comments
Can someone answer this question? Or point out if there is something unreasonable? |
Hi! I see no problem with exposing timezone params in You can contribute by making PR with this change
Don't really understand issue here, this code just makes sure that you use only one of init methods, as we wouldn't know how to parse it if several are provided at the same time |
My bad, I just don't know why adding
Alright, I will create a new pull request for adding |
Currently, you can use the @asynccontextmanager
async def lifespan(app: FastAPI):
async with RegisterTortoise(
app,
config={
"connections": {"default": DB_URL},
"apps": {"models": {"models": ["models"]}},
"use_tz": True,
"timezone": "Asia/Shanghai",
"generate_schemas": True,
},
):
yield |
The feature has been extended in pr #1649 |
Is your feature request related to a problem? Please describe.
I use mysql in my project and the I use
db_url
andRegisterTortoise
to initialize the database connection. And then when I executecreate
on myModel
, the new record is inserted into database, while theupdate_time
is 8 hours behind the current time. That means that I need to set mytimezone
toAsia/Shanghai
anduse_tz
toFalse
cause I am in East 8 TimeZone.But unfortunately I don't find the appropriate way to do that. I try to add timezone in
db_url
string, like this:mysql://root:123456@192.100.30.102:3306/energy_dispatch?charset=utf8&timezone=Asia/Shanghai
, and the code is reported an error:I dig into the source code, and I do some changes here:
after that, I tried again and the time in db is correct now.
Describe the solution you'd like
I'm not sure this is a good choice to expose
timezone
anduse_tz
params toRegisterTortoise
class.and I surely want to know If the
db_url
andconfig
andconfig_file
is identical each other?If I select
db_url
to initialize my connection and how to config thetimezone
anduse_tz
and others, etc.I'd be appreciate if anyone could help clarify these confusions.
The text was updated successfully, but these errors were encountered: