Comments (3)
I agree with the comment on #590 that it is not Graphene's responsibility to define a default timezone for datetime values.
While I understand the potential issues that can arise from handling timezone-unaware datetimes, it is ultimately the responsibility of the developer to ensure that timezone aware datetimes are properly resolved for any DateTime types. Additionally, if the datetime value is not timezone aware, we cannot assume that it is in UTC.
Defining a default server timezone could potentially misrepresent the actual timezone for the underlying value, and as stated in issue #590, UTC should not be the default timezone. It is best to leave the responsibility of handling timezone-aware datetimes to the developer and not the framework.
The DateTime
Scalar uses datetime.isoformat
internally to convert datetime
objects into ISO8601-compliant strings. This function includes an UTC-Offset if datetime.tzinfo
is specified on the datetime object. Is there any reason why you can't set tzinfo
yourself? You could easily extend the existing DateTime
scalar, too.
Other than that, I agree with the points stated in #590. DateTime
time zone settings should be an issue solved in userland.
from graphene.
Is there any reason why you can't set tzinfo yourself?
If it's coming from a database that doesn't store timezone info and assumes UTC.
You could easily extend the existing DateTime scalar, too.
Yes this is a work-around that needs to be handled on a case by case basis when it's discovered.
When using tools like graphene-sqlalchemy
, the queries are auto-generated via this code, relying on graphene.DateTime
.
Defining a default server timezone could potentially misrepresent the actual timezone for the underlying value, and as stated in issue #590, UTC should not be the default timezone.
That's true. However, the following assumptions are required for the existing timezone-unaware DateTime object not to be misrepresented:
- the client sends the datetime without tzinfo to the server and expects the server to send back that datetime as-is
- the client doesn't expect clients in other timezones to interact with it
If either of these assumptions turn out not to be true, then either the data the client saves won't be the same as what they get back, or the meaning of the datetime will be different for clients across different timezones (they'll both see e.g. 9pm in their respective timezones).
from graphene.
I've been digging further into this. I think this is a broader issue with some database implementations, in particular MySQL
<-> SQLAlchemy
, which in turn leads to problems resolving graphene.DateTime
through graphene-sqlalchemy
.
While still I think the current use case is a problem, I agree that graphene
is not necessarily the place to resolve the issue, and this problem is more relevant at the sqlalchemy
/graphene-sqlalchemy
level.
from graphene.
Related Issues (20)
- Thanks for Thanks for GraphQL Python Roadmap HOT 1
- Leading white spaces in description casuing issues HOT 1
- `graphql_schema` introspection doesn't output docstrings descriptions
- InputObjectType causing encoding issues with JSONField HOT 1
- @include and @skip directives lead to irrelevant errors HOT 2
- Turning Non-null to is_null HOT 3
- Enum conversion to Graphene Enum fails if Enum name is "type" HOT 1
- Enum equality comparison is inconsistent
- http://www.graphene-python.org Has EXPIRED HOT 3
- Upload file HOT 2
- Unexpected argument in Pycharm 2023.2.1 HOT 1
- Default_value option in Arguments inside Mutation is not working as expected HOT 2
- Exception: NonNull could not have a mounted String() as inner type. Try with NonNull(String).
- Returning non fatal errors alongside data HOT 1
- Conversion to snake_case fails on nested inputs
- Depth limit validator key error if fragment undefined
- Tests in `graphene/relay/tests/test_custom_global_id.py` fail due incompatibility with pytest 8.x HOT 2
- Enum.from_enum() fails with Django IntegerChoices
- Do you support GQL over websocket? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene.