Skip to content

Fix inc/dec rejecting deltas outside a field's min_value/max_value - #2914

Open
DSeaStar wants to merge 1 commit into
MongoEngine:masterfrom
DSeaStar:fix-2339-inc-dec-min-value
Open

Fix inc/dec rejecting deltas outside a field's min_value/max_value#2914
DSeaStar wants to merge 1 commit into
MongoEngine:masterfrom
DSeaStar:fix-2339-inc-dec-min-value

Conversation

@DSeaStar

Copy link
Copy Markdown

Summary

  • $inc / $dec apply a delta, not the stored field value. prepare_query_value() was still running validate(), so a field with min_value=0 rejected any decrement (dec__amount=10 → delta -10 → "value is too small"). The same happens for inc when max_value is set.
  • Skip min/max (and other stored-value) validation for the inc/dec operators only. set and other update operators still validate as before.
  • Fixes dec atomic operation on Float/Decimal/Int Field is broken #2339 (also noted in Atomic update affected by min_value validation #2403). Maintainer confirmed: min_value should not apply to inc/dec.

Test plan

  • transform.update(Account, dec__amount=10) on FloatField(min_value=0) now emits {'$inc': {'amount': -10.0}}
  • Same for IntField / DecimalField decrements
  • set__amount=-1 still raises ValidationError
  • Added test_transform_update_inc_dec_ignores_min_max

$inc/$dec apply a delta, not the stored value, so min/max validation
must not run against the increment (see MongoEngine#2339).
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.

dec atomic operation on Float/Decimal/Int Field is broken

1 participant