Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24489 closed Uncategorized (invalid)

PositiveIntegerField accepting Negatives

Reported by: projectgoav Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: Models Fields PositiveIntegerField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The PositiveIntegerField seems to accept negative values when tested

Full Problem: StackOverflow

Change History (1)

comment:1 by Marten Kenbeek, 10 years ago

Resolution: invalid
Status: newclosed

I'm marking this as invalid:

  • Most validation is not handled by the model, but rather by the database and model forms. Model forms enforce the minimal value.
  • The documentation makes no claims on which values are not supported, only on which values are guaranteed to be supported. Other than that, it is backend-dependant. SQLite does not enforce any restrictions, but most other backends do.
  • The value on a model is never changed by saving it, so post.views will always be -10 instead of the actual database value. For MySQL and probably other backends, the value is correctly set to 0 when reloaded from the database.

So while it might be semantically incorrect to support negative values, it's not a bug, and changing it would be backwards-incompatible. Feel free to add a note to the documentation, though.

Last edited 10 years ago by Marten Kenbeek (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top