Commit Graph

172 Commits

Author SHA1 Message Date
Michael
79b2350b54 [fields] Format error message only if params exist (#6624)
This prevents exceptions when the error message contains `%`, but is
not intended for formatting.  Django itself does the same:
6866c91b63/django/core/exceptions.py (L168-L169)

Fixes encode/django-rest-framework#6622
2019-07-01 13:28:16 +01:00
Ryan P Kilby
7179ea9984 Raise exception when field source is a built-in (#6766) 2019-07-01 13:25:47 +01:00
Ryan P Kilby
91ea138406 Allow redundant SerializerMethodField method names (#6767) 2019-07-01 13:22:03 +01:00
Ran Benita
ccd9b71c0a Don't cache _readable_fields and _writable_fields (#6689)
It might be useful for a serializer with many many fields which uses
read_only and write_only on a large percentage of the fields. But the
memory usage and statefulness it adds are not worth it for the common
case.
2019-05-21 15:45:31 +01:00
gaetano-guerriero
a7c577cb31 Dict field allow empty (#6583)
* dict field: support allow_empty option

* document ListField allow_empty option

* document HStoreField allow_empty parameter
2019-05-09 09:18:20 +01:00
Asif Saif Uddin
50a24d6d7f Drop Python 3.4 support (#6620) 2019-05-06 11:35:58 -07:00
Carlton Gibson
0407a0df8a
Dropped Python 2 compatibility. (#6615)
Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com>
2019-04-30 17:53:44 +02:00
Jon Dufresne
1a0a8dde00 Correct misspelled module 'typing' (#6616)
https://docs.python.org/3/library/typing.html
2019-04-30 09:44:01 +01:00
Si Feng
1ece516d2d Adjusted field validators to accept iterables. (#6282)
Closes 6280.
2019-02-19 16:38:20 +01:00
Jerome Leclanche
0eb2dc1137 Prohibit null characters in CharField by default (#6073)
* Implement an allow_null_bytes argument to CharField (default True)
* Switch to using native ProhibitNullCharactersValidator instead
2018-10-02 16:54:15 +02:00
Ryan P Kilby
fc6cbb5b26 Allow nullable BooleanField in Django 2.1 (#6183)
* Add tests for BooleanField when nullable

* Allow nullable BooleanField in Django 2.1

* Drop 'BooleanField.allow_null' check

* Remove conflicting false/null values
2018-09-13 17:25:03 +01:00
Ryan P Kilby
a628a2dbce Drop Django 1.10 support (#5657)
* Remove Django 1.10 from CI

* Remove Django 1.10 compat code
2018-07-06 12:14:31 +02:00
Daniel Hahler
3578bd6883 get_error_detail: use error_dict/error_list (#5785) 2018-07-06 10:44:58 +02:00
Noam
7268643b25 min_value/max_value support in DurationField (#5643)
* Added min_value/max_value field arguments to DurationField.
* Made field mapping use mix/max kwargs for DurationField validators.
2018-04-24 09:24:05 +02:00
Sascha P
7d64b7016d Removed input value from deault_error_message (#5881) 2018-04-20 16:00:27 +02:00
Christian Kreuzberger
f148e4e259 Ensure that html forms (multipart form data) respect optional fields (#5927) 2018-04-20 15:11:52 +02:00
Ryan P Kilby
7078afa42c Change ISO 8601 date format to exclude year/month (#5936) 2018-04-14 05:23:31 +01:00
Carlton Gibson
c2b24f83a3
Alter read_only+default behaviour (#5886)
* Always exclude read_only fields from _writable_fields

* Remove `read_only` from `CreateOnlyDefault` example.
      In this context (without mentioning `save`) now slightly misleading.
2018-03-20 21:09:31 +01:00
Carlton Gibson
da535d31dd
Fixed active timezone handling for non ISO8601 datetimes. (#5833)
* Add failing test for to_representation with explicit default timezone

See discussion here:
    https://github.com/encode/django-rest-framework/pull/5435#issuecomment-364054509

* Always run enforce_timezone
2018-02-16 16:47:49 +01:00
Ryan P Kilby
2709de1310 Add HStoreField, postgres fields tests (#5654)
* Test postgres field mapping

* Add HStoreField

* Ensure 'HStoreField' child is a 'CharField'

* Add HStoreField docs
2018-01-15 15:52:30 +01:00
Jon Dufresne
ffe3dbb1b1 Perfer iter(dict) over iter(dict.keys()) (#5736)
Calling dict.keys() is unnecessary. The two are functionally equivalent
on modern Pythons.

Inspired by Lennart Regebro's talk "Prehistoric Patterns in Python" from
PyCon 2017.

https://www.youtube.com/watch?v=V5-JH23Vk0I
2018-01-08 09:49:46 +00:00
Ryan P Kilby
6bd773e7f8 Improve composite field child errors (#5655)
* Fixup DictField test descriptions

* Nest ListField/DictField errors under the idx/key

* Add nested ListField/DictField tests
2018-01-02 10:45:59 +01:00
Jon Dufresne
ff556a91fd Remove references to unsupported Django versions in docs and code (#5602)
Per the trove classifiers, DRF only supports Django versions 1.10+. Can
drop documentation, code comments, and workarounds for older Django
versions.
2017-11-20 09:35:54 +01:00
Sergei Azarkin
d49d796c85 Change ImageField validation pattern, use validators from DjangoImageField (#5539) 2017-11-06 11:14:37 +01:00
Jon Dufresne
0552810410 Use dict and set literals instead of calls to dict() and set() (#5559)
Set literals are available on all supported Python versions. They are
idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop

$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop
2017-11-06 10:03:01 +01:00
Carlton Gibson
331c31370f
Add rounding parameter to DecimalField (#5562)
* Adding rounding parameter to DecimalField.

* Using standard `assert` instead of `self.fail()`.

* add testcase and PEP8 multilines fix

* flake8 fixes

* Use decimal module constants in tests.

* Add docs note for `rounding` parameter.
2017-11-06 09:55:09 +01:00
Stephen Chisholm
93e75ec138 Catch OverflowError for "out of range" datetimes (#5546)
* Add test for #5545 
* Catch OverflowError for "out of range" datetimes
2017-10-31 10:17:08 +01:00
Ryan P Kilby
b64f8066c0 Add json util wrapper, failing JSONField test 2017-09-25 09:08:20 +02:00
Carlton Gibson
7d6d043531 Fix DateTimeField TZ handling (#5435)
* Add failing TZ tests for DateTimeField

- tests "current" timezone activation
- tests output for non-UTC timezones

* Update DateTimeField TZ aware/naive test output

* Fix DateTimeField TZ handling

* Add Release Note for BC change
2017-09-20 12:15:15 +02:00
Jeremy Nauta
c0a48622e1 Allow ChoiceField.choices to be set dynamically (#5426)
## Description

The `choices` field for the `ChoiceField` class should be able to be edited after `ChoiceField.__init__` is called.

```
field = ChoiceField(choices=[1,2])
field.choices = [1]  # Should no longer allow `2` as a choice
```

Currently, you must update `choices`, `grouped_choices`, and `choice_strings_to_values` to achieve this. This P/R keeps `grouped_choices` and `choice_strings_to_values` in sync whenever the `choices` are edited.
2017-09-20 11:33:50 +02:00
Ryan P Kilby
ae95ed1ec2 Add repr(value) to the assert msg in FieldValues 2017-09-11 05:18:39 -04:00
Igor Tokarev
79be20a7c6 Updated supported values for the NullBooleanField (#5387)
* Updated supported values for the NullBooleanField.
* Added check for unhashable types in NullBooleanField.
2017-09-04 10:11:53 +01:00
Ryan P Kilby
26ebb88306 Revert 3288 (#5313)
* Add regression test for #2505. Thanks @pySilver!

* Add regression test for #5087

* Revert "Cached the field's root and context property."

This reverts commit 792005806b.
2017-08-07 16:52:09 +01:00
Tom Christie
6d4d4dfd04 Ensure closables in request.FILES get closed. (#5262)
Ensure closables on `.FILES` get closed.
2017-07-10 13:42:02 +01:00
Tom Christie
39f6f1137c Merge pull request #5261 from encode/validation-error-on-invalid-timezone-parsing
Raise validation error on invalid timezone parsing.
2017-07-10 11:27:28 +01:00
Tom Christie
41901185d2 Ignore timezone test case for Django 1.8, due to differing behavior. 2017-07-10 11:18:26 +01:00
Tom Christie
7d240a2e50 Minor cleanup in test. 2017-07-10 10:30:39 +01:00
Tom Christie
c7e2bad524 Merge pull request #5189 from myrubapa/master
Fix API documentation templates do not check for user authentication #5162
2017-07-10 10:28:33 +01:00
Tom Christie
bf7fcc495b Raise validation error on invalid timezone parsing. 2017-07-10 10:14:31 +01:00
dmmatson
302a9d089e Fixed tests on Windows. Added unicode support to SlugField 2017-06-23 23:11:17 -06:00
Bekhzod Tillakhanov
84e22cc2f3 Scheme fix when unauth and Flask8 lint fix 2017-05-30 00:15:07 +05:00
Sergey Petrunin
b0a0c30bfe Added pytz exception in compat module.
Mock pytz.timezone localize in tests.
Ref: #4986
2017-03-22 00:03:32 -04:00
Sergey Petrunin
e4a1bd140b Update error message.
Ref: #4986
2017-03-20 18:47:25 -04:00
Sergey Petrunin
d4726dab81 Fix bug for not existent or ambiguous datetime during native to aware conversion in timezone with DST.
Ref: #4986
2017-03-18 23:13:26 -04:00
Sergey Petrunin
1ee54fb85c Added test for DateTimeField validation when server has timezone with DST and input is a native time in a DST shift interval.
Added pytz to requirements-testing.txt to reproduce the case.
2017-03-15 23:45:41 -04:00
李扬
cbad236f6d Add max_length and min_length arguments for ListField (#4877) 2017-02-06 09:36:03 +00:00
Mariusz Felisiak
5c0f9f147c Removed unnecessary utc wrapper. (#4839) 2017-01-23 16:22:32 +00:00
Asif Saifuddin Auvi
026a8d8707 make lint happy with isort --recursive 2017-01-18 22:15:44 +06:00
Asif Saifuddin Auvi
006ae46092 remove trailing comma 2017-01-18 21:40:07 +06:00
Asif Saifuddin Auvi
326e09dde9 added utc compat to tests of fields 2017-01-18 20:01:18 +06:00