Ticket #26949: 0001-Fix-disabled-forms.JSONField-crash-with-TypeError.patch

File 0001-Fix-disabled-forms.JSONField-crash-with-TypeError.patch, 810 bytes (added by Olexander Yermakov, 8 years ago)

As I see the problem with previous fix was because assumption that initial values are already cleaned is wrong. I added these lines to omit json.loads() for disable field. But I think that's the obvious fix, means there are downsides here if it's not been done before, so I'm not sure about it. Could you, please, advice what could be wrong with this approach? Thanks!

  • django/contrib/postgres/forms/jsonb.py

    From b1fd0ac2392ae8cb2780e6b51dfe1b9bef8ff1ec Mon Sep 17 00:00:00 2001
    From: Olexander Yermakov <mannavard1611@gmail.com>
    Date: Tue, 26 Jul 2016 14:14:36 +0300
    Subject: [PATCH] Fix disabled forms.JSONField crash with TypeError
    
    ---
     django/contrib/postgres/forms/jsonb.py | 3 +++
     1 file changed, 3 insertions(+)
    
    diff --git a/django/contrib/postgres/forms/jsonb.py b/django/contrib/postgres/forms/jsonb.py
    index 415288d..609112c 100644
    a b class JSONField(forms.CharField):  
    2121        super(JSONField, self).__init__(**kwargs)
    2222
    2323    def to_python(self, value):
     24        if self.disabled:
     25            return value
     26
    2427        if value in self.empty_values:
    2528            return None
    2629        try:
Back to Top