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

auto_now_add=True Fields do not match baker.make return #469

Open
nweave03 opened this issue Dec 28, 2023 · 0 comments
Open

auto_now_add=True Fields do not match baker.make return #469

nweave03 opened this issue Dec 28, 2023 · 0 comments

Comments

@nweave03
Copy link

Describe the issue
A clear and concise description of what the issue is.

I am using Django 5.0, and found what I think is a bug. This does not occur if i fall back to model_bakery 1.16.0, it was introduced in 1.17.0. I searched but I did not see anything on it. Apologies if i just missed it, or if this is expected behavior and I didn't see the changelog on it.

When using a Djano DateTimeField with auto_now_add=True like so:


   created = models.DateTimeField(
        auto_now_add=True, db_index=True, verbose_name=_("created")
    )

The baker.make return does not match what is in the database.

baker.make return:
{'_state': <django.db.models.base.ModelState object at 0x1158fb650>,
'created': datetime.datetime(2023, 12, 28, 18, 49, 21, 667003, tzinfo=datetime.timezone.utc),
}

objects.all()[0].dict return:
{'_state': <django.db.models.base.ModelState object at 0x1157bf990>,
'created': datetime.datetime(2023, 12, 28, 18, 49, 21, 666729, tzinfo=datetime.timezone.utc),
}

To Reproduce

Create any model with an auto_now_add time field. Then compare the output of the baker.make function with what is in the database. They do not match.

Expected behavior
I expect that the baker.make function returns an instance of the database object. I use this for comparisons with tests. When the datetime fields do not match, I have to look for the error.

Versions

  • Python: 3.11
  • Django 5.0
  • Model Bakery 1.17.0 (does not occur in 1.16.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant