Comments (5)
well.. I've found __dates__
magic field, but I'm really wonder why do I have to explicitly mention that I wan't to cast everything in one type... ? It's kinda really strange solution.
from orm.
coming back to this issue... still having problems with it...
In [27]: s = SomeModel.first()
In [28]: s.token_expires_at
Out[28]: DateTime(2022, 12, 19, 19, 35, 23, tzinfo=Timezone('Europe/Berlin'))
In [29]: type(s.token_expires_at)
Out[29]: pendulum.datetime.DateTime
In [30]: new_session = SomeModel()
In [31]: new_session.token_expires_at = pendulum.now()
In [32]: new_session.token_expires_at
Out[32]: '2022-12-20 11:06:29'
In [33]: type(new_session.token_expires_at)
Out[33]: str
from orm.
Why does datetime field can be returned as three different types? - I've seen str
, datetime
, and pendulum.datetime.DateTime
already... should I expect to see unix epoch at some point?
from orm.
moreover it's being serialized into different formats:
In [31]: new_session.token_expires_at = pendulum.now()
In [32]: new_session.token_expires_at
Out[32]: '2022-12-20 11:06:29'
while existing models serialized with .serialize()
gets format:
'token_expires_at': '2022-12-08T13:20:06+01:00',
this is extremely frustrating
from orm.
the logic of this is on line 822 of the Model class.
after looking at these examples more closely. most of the examples i believe is how the IDE is representing the classes object as a string.
the only thing that actuallt threw me for a trip was this line
In [30]: new_session = SomeModel()
In [31]: new_session.token_expires_at = pendulum.now()
In [32]: new_session.token_expires_at
Out[32]: '2022-12-20 11:06:29'
this is a bit confusing but its how the model class is converting the datetime to get ready for saving the date to the database (as a string). that part happens.
you can actually modify this behavior in your own application by overriding tis method on your model to this:
def get_new_datetime_string(self, _datetime=None):
"""
Given an optional datetime value, constructs and returns a new datetime string.
If no datetime is specified, returns the current time.
:rtype: list
"""
return _datetime
this would not convert the datetime immediately to a string.
this change in the package actually doesn't fail any tests but with that being said i don't feel comfortable making that change right now.
i believe that when setting a date onto a model to be later saved, it should be manipulated before saving it onto the model.
from orm.
Related Issues (20)
- Add complete type definitions HOT 1
- masoniteorm.query.QueryBuilder.QueryBuilder.create() HOT 12
- Ability to define custom computed properties on models HOT 2
- __fillable__ and __guarded__ are mutually exclusive... why? HOT 4
- Little issue in first_or_create method HOT 3
- Automatically remember the user who created or updated HOT 1
- TypeError exception when running `seed:run` HOT 2
- Where with None values
- Error trying to save Json in version 2.19.* HOT 1
- Implement migrate:fresh
- Allow for specifying a config path when using ConnectionResolver
- Change default folder
- Changing a column on sqlite from integer to varchar removes data types on unsigned integer columns
- Add min to collection. HOT 1
- Postgres psycopg2 TLS connectivity HOT 1
- Update to Pendulum 3 HOT 1
- Add JSON structure to where clause.
- Add Enum column in migration not working (MySQL) HOT 3
- Use actual enum in Postgres Plateform instead of varchar with checks
- Use `ALTER` statement for dropping and renaming colmuns
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 orm.