Skip to content

fix: should not skip auto now fields but assign with specified value#520

Merged
amureki merged 1 commit intomodel-bakers:mainfrom
mattwang44:fix-#519
Feb 26, 2025
Merged

fix: should not skip auto now fields but assign with specified value#520
amureki merged 1 commit intomodel-bakers:mainfrom
mattwang44:fix-#519

Conversation

@mattwang44
Copy link
Contributor

@mattwang44 mattwang44 commented Feb 22, 2025

Describe the change
Fix #519, which is a regression introduced in #507.

  • The auto now fields should not be skipped in _skip_field(). Instead, assign the specified value to the resulting instance.
  • Add test cases (modified from those provided by @hoefling in #519).

PR Checklist

  • Change is covered with tests
  • CHANGELOG.md is updated if needed

@mattwang44 mattwang44 force-pushed the fix-#519 branch 5 times, most recently from 765364b to 3353a8c Compare February 22, 2025 15:15
@mattwang44 mattwang44 marked this pull request as draft February 22, 2025 15:23
@mattwang44 mattwang44 marked this pull request as ready for review February 22, 2025 15:26
@amureki amureki requested a review from Copilot February 26, 2025 20:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes a regression that prevented assigning specified values to auto now fields by modifying the field handling in Baker. Key changes include:

  • Removing the automatic skipping of auto now fields in _skip_field.
  • Updating _handle_auto_now to perform a forced update via the model’s manager and then manually assign the specified values.
  • Adding new test cases for auto now fields in both recipes and baker tests, and updating the CHANGELOG accordingly.

Reviewed Changes

File Description
tests/test_recipes.py Added TestAutoNowFields with two test cases using different value generators.
model_bakery/baker.py Removed skip for auto now fields in _skip_field and revised _handle_auto_now to update and assign fields.
tests/test_baker.py Extended tests to assert that auto now fields remain unchanged after refresh.
CHANGELOG.md Documented the fix for the regression regarding auto now field updates.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Copy link
Member

@amureki amureki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change!
This indeed feels like a better solution, thanks for the fix @mattwang44

@amureki amureki merged commit 096742d into model-bakers:main Feb 26, 2025
10 checks passed
@mattwang44 mattwang44 deleted the fix-#519 branch February 27, 2025 03:01
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

Successfully merging this pull request may close these issues.

Regression for DateField/DateTimeField in 1.20.3

3 participants