Closed Abeautifulsnow closed 1 week ago
Can someone answer this question? Or point out if there is something unreasonable?
Hi!
I see no problem with exposing timezone params in RegisterTortoise
Not sure why it wasn't added in the first place, probably contributor just forgot about it
You can contribute by making PR with this change
and I surely want to know If the db_url and config and config_file is identical each other?
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
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 timezone
to db_url
is causing an error, and I'm confused about whether all three are the same.
You can contribute by making PR with this change
Alright, I will create a new pull request for adding time_zone
and use_tz
in RegisterTortoise
.
Currently, you can use the config
argument:
@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.