Opened 9 years ago

Closed 7 years ago

#1553 closed defect (wontfix)

[patch] missing validate and to_python methods

Reported by: Nebojsa Djordjevic <nesh at studioquattro dot co dot yu> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: nesh@…, freakboy3742@…, andrew@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

As already discussed in django-devel.

I'll soon post a patch here, stay tuned.

Attachments (3)

fields.py (19.2 KB) - added by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu> 9 years ago.
unit-tests for model fields (put this in <django root>/test/othertests/fields.py)
new-fields.py (12.9 KB) - added by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu> 9 years ago.
new unittests (I can't replace old ;( )
fields.diff (9.2 KB) - added by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu> 9 years ago.
patch for db/models/fields/init.py

Download all attachments as: .zip

Change History (23)

comment:1 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

  • CommaSeparatedIntegerField - what is the preffered return value for this? To me, most logical thing is that this returns a int list or [] (or maybe a None if allowed) for empty field.

comment:2 Changed 9 years ago by adrian

For CommaSeparatedIntegerField, it makes sense to return an int list, and an empty list if there aren't any values.

comment:3 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

huh, all day of the meetings with the clients :(, I hope that I'll finish the most of the field validator/to_python stuff (except of the related fields) and post a patch tomorrow.

comment:4 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

btw. why validate error messages (in fields.init.py) sometime use gettext and sometime gettext_lazy?

comment:5 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

First thing first. Here are unit-tests (test/othertests/fields.py) for field classes (mostly for to_python and validate).

Currenttly this tests are not implemented:

  • FileField
  • FilePathField
  • ImageField
  • PhoneNumberField
  • USStateField
  • TestXMLField


And all for the related fields.

Let me know if I'm on the right track because I'll start to implement missing to_pyhon and validate methods shortly.

Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

unit-tests for model fields (put this in <django root>/test/othertests/fields.py)

Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

new unittests (I can't replace old ;( )

Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

patch for db/models/fields/init.py

comment:6 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

  • Summary changed from missing validate() methods to [patch] missing validate() methods

Here is my first attempt to add missing validate and to_python methods.

It passes my unit-tests and also passes all other tests from the test directory.

No related fields because I'm not sure how to make to_python for them. Pointers?

comment:7 Changed 9 years ago by Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>

  • Summary changed from [patch] missing validate() methods to [patch] missing validate and to_python methods

comment:8 Changed 9 years ago by russellm

  • Cc freakboy3742@… added
  • Component changed from Metasystem to Database wrapper
  • Owner changed from adrian to russellm
  • Version changed from magic-removal to SVN

Apologies for this going stale for so long. The fixes you have sumbitted here are almost essential to get the serialization framework working at 100%, which it will need to be in order to get test fixtures working (See #2333). I'll see if I can shepard these fixes into trunk.

comment:9 Changed 9 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Accepted

Accepted for russellm to merge in #2333.

comment:10 Changed 9 years ago by russellm

  • Triage Stage changed from Accepted to Design decision needed

The 'acceptance' I gave is now stale - it turns out this fix isn't needed for #2333, and validation is going through a bit of a rework in the light of newforms validation. The future plans for model-level validation need to be confirmed.

comment:11 Changed 9 years ago by Andrew Sutherland <andrew@…>

  • Cc andrew@… added

XML serialization still needs the to_python methods; should this be split out into a separate bug ignoring the validation changes of this patch? (I had logged #2893 because of the problems caused by the lack of the methods, but closed it in favor of this bug.)

comment:12 Changed 8 years ago by Nebojša Đorđević <nesh@…>

  • Cc nesh@… added; nesh@… removed

comment:13 Changed 8 years ago by Good gay!

  • Cc openbfor@… added; nesh@… freakboy3742@… andrew@… removed
  • Component changed from Database wrapper to Admin interface
  • Keywords None added
  • Triage Stage changed from Design decision needed to Accepted
  • Version changed from SVN to 0.96

Not bad man! Look what i founf hier!!!!!

  • будет брать все обьявы из файлы - будет брать все обьявы из файлы - будет брать все обьявы из файлы - будет брать все обьявы из файлы

comment:14 Changed 8 years ago by Good gay!

  • Component changed from Admin interface to Contrib apps
  • Triage Stage changed from Accepted to Design decision needed
  • Version changed from 0.96 to unicode

Not bad man! Look what i founf hier!!!!!

  • будет брать все обьявы из файлы - будет брать все обьявы из файлы - будет брать все обьявы из файлы - будет брать все обьявы из файлы

comment:15 Changed 8 years ago by Simon G. <dev@…>

  • Cc nesh@… freakboy3742@… andrew@… added; openbfor@… removed
  • Component changed from Contrib apps to Database wrapper
  • Keywords None removed
  • Version changed from unicode to SVN

spam cleanup on aisle 3.

comment:16 Changed 8 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

I'm on top of validation, and this no longer applies to the current approach.

comment:17 Changed 7 years ago by andrewbadr

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Lack of to_python on IntegerField is breaking our tests when reading from XML fixtures.

From what I can tell, this how things are supposed to work: (1) an IntegerField is read as unicode (from an XML fixture), (2) the row is saved to the database, and (3) field is an integer on the next read from db. However, on one model, we have a post-save signal handler that expects the field to be an integer. This handler throws an exception when it gets unicode, so our tests break.

Is accepting strings a part of the database interface definition? I'm guessing we'd hit this same problem if using a form.

I know this was already closed as wontfix, but there was no concrete justification for the need at that time.

comment:18 Changed 7 years ago by russellm

  • Resolution set to wontfix
  • Status changed from reopened to closed

Please don't reopen tickets closed as wontfix. This ticket was closed because it was talking about validation, and was closed because it has been superceded by ticket #6845. Your issue is about missing to_python methods causing issues with serialization. Since you have found a new bug, you should open a new ticket.

comment:19 Changed 7 years ago by andrewbadr

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Sorry. In case anyone finds this, the new ticket is #8298.

comment:20 Changed 7 years ago by andrewbadr

  • Resolution set to wontfix
  • Status changed from reopened to closed

Er, I don't know why Trac did that.

Note: See TracTickets for help on using tickets.
Back to Top