Skip to content

Date column causes pendulum exception #465

Closed
@tpow

Description

@tpow

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn existing feature is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions