Skip to content
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

Date column causes pendulum exception #465

Closed
tpow opened this issue Jun 9, 2021 · 1 comment · Fixed by #466
Closed

Date column causes pendulum exception #465

tpow opened this issue Jun 9, 2021 · 1 comment · Fixed by #466
Labels
bug An existing feature is not working as intended

Comments

@tpow
Copy link

tpow commented Jun 9, 2021

As mentioned on Slack earlier today, I have a Person model that is defined with a date column (not datetime). When trying to retrieve it with a query like users = User.with_("person", "name", "roles").order_by('last_active_at', 'desc').get() it throws an exception in Pendulum "instance() only accepts datetime objects." (I suspect it would do this even when querying the Person directly, but I haven't tried.)

The model has the date of birth (DOB) column indicated as a date type:

class Person(Model):                                                             
    """Person Model."""                                                          
    __table__ = 'people'                                                         
    __dates__ = ['dob']

For columns that are defined as date or datetime in the database, I haven't found it necessary to specify __dates__ in the model, but I tried it here anyway. Perhaps I'm misunderstanding what this does or when it is needed. I suspect it is mainly for fields that are strings/char types holding date information.

What database are you using?

  • Type: MySQL
  • Masonite ORM v1.0.48

Additional context
It looks like date types need to be handled in the get_new_date method before this line

return pendulum.instance(datetime, tz=self.__timezone__)

Joseph mentioned the pendulum issue #250 which seems to be the problem. This could be fixed in either the Masonite ORM Model or in pendulum.

Querying and using this date column was working fine with Masonite 2 using Orator ORM. (I am working on migrating the code to Masonite 3.) I believe Orator handled the date types before it did its "hydration" step. Perhaps it would be worthwhile to look at what it did.

@tpow tpow added the bug An existing feature is not working as intended label Jun 9, 2021
@josephmancuso
Copy link
Member

@tpow This is fixed in version 1.0.49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants