Opened 4 years ago

Closed 4 years ago

#17125 closed New feature (fixed)

The regex of an existing RegexField cannot be changed

Reported by: claudep Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: regexfield
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, once you have instanciated a RegexField with a regex, it is not possible to change it afterwards (without big hacks).

Attachments (1)

17125.1.diff (2.0 KB) - added by claudep 4 years ago.
Allow modification of regex after RegexField init

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by claudep

Allow modification of regex after RegexField init

comment:1 Changed 4 years ago by claudep

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by claudep

  • Patch needs improvement set

I might have been a little too naive in my implementation. There seems to be a bunch of deepcopy issues when adding properties to form fields. More experts opinions welcome...

comment:3 Changed 4 years ago by claudep

After some investigation, it appears that the field validators list is shared between form base_fields and instance fields. When I modify validators in _set_regex, the base_fields 'url' validators list is also modified, hence future calls to create new forms will have a modified validators list, which is not intended.
If I subclass __deepcopy__ and add result.validators = self.validators[:], the problem I had disappears.
Is it a bug, a feature? Did I miss something?

comment:4 Changed 4 years ago by claudep

Problem with validators shared between form instances entered in #17127.

comment:5 Changed 4 years ago by claudep

  • Patch needs improvement unset

The issue I had has been resolved in #17127. So the patch is still valid.

comment:6 Changed 4 years ago by julien

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:7 Changed 4 years ago by julien

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

In [17076]:

Fixed #17125 -- Made it possible to change a RegexField's regular expression validator after it has been initialized. Thanks to Claude Paroz for the report and patch.

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