Comments (2)
Yes, this is a bug in wq.db's ModelSerializer
, which converts all incoming ""
to None
before running the validation. A temporary workaround would be to create a custom ModelSerializer
that restores the blank value:
# myapp/serializers.py
from wq.db.rest.serializers import ModelSerializer
class MyModelSerializer(ModelSerializer):
def to_internal_value(self, data):
result = super().to_internal_value(data)
if result.get('fieldname', None) is None:
result['fieldname'] = ""
return result
# myapp/rest.py
from wq.db import rest
from .serializers import MyModelSerializer
from .models import MyModel
rest.router.register_model(
MyModel,
serializer=MyModelSerializer,
)
The longer term fix is a bit more complicated. The issue narrows down to the fact that wq.db's ModelSerializer
uses the HTML JSON Forms parser to handle potentially nested records. This processing happens early, so that by the time the validators run, the data is treated as if it had been submitted via a JSON API. Since JSON differentiates between null
and ""
, but HTML does not, I had to make an arbitrary decision how to handle empty strings when converting from an HTML Form submission to JSON (see this function). I chose to treat all empty strings as null, since that was the more common interpretation in my usage. The downside is that blank=True
doesn't work at all.
Django REST Framework itself does not suffer from this constraint, because it has access to both the field properties and the structure of the input data at the same time (see this function). When is_html_input()
is run on a dictionary that has already been processed by HTML JSON forms, it returns False
, so the allow_blank
handling code doesn't run.
If you aren't using nested serializers you technically don't need HTML JSON Forms at all, though I don't currently have an easy way to disable the functionality.
from wq.db.
Another workaround: I noticed that if I set value of these non-nullable text fields to " " (a space), they are stored in the database as empty strings (without conversion to NULL).
from wq.db.
Related Issues (20)
- add_lookups: only pull in id and label for related items HOT 1
- alternative for method overridding
- no user profile information available in login.json HOT 2
- don't assume nested serializers always have get_wq_config
- server equivalent of wq/app.js _default_attachments
- list_exclude causes fields to not show up in config HOT 6
- update python-social-auth
- default_attachments not passing query string parameters to get_lookup_choices
- Handling of context misses for type filters HOT 4
- BooleanField and NullBooleanField treated as type=string with dump_config HOT 2
- wq.db.rest.serializers.ModelSerializer's context contains no request HOT 4
- Django 2 support
- Django REST framework requires details field HOT 1
- result_inline.html character encoding issue HOT 2
- DRF 3.10 breaking change HOT 1
- Custom OAuth authentication
- Issue in SPATIALITE_LIBRARY_PATH for Windows os HOT 1
- STATIC Contents are loading HOT 1
- Django 3.1 compatibility HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wq.db.