Commit Graph

8012 Commits

Author SHA1 Message Date
Ran Benita
1dc4caac65 Avoid Django's lazy() when creating validators because it is too slow
As a fix for issue #3354, commit 607e4edca7 made the
evaluation of some validation error messages lazy. To achieve that,
Django's django.utils.functional.lazy() function was used. However, that
function is extremely heavy and slow, and slows down string validation
significantly (lazy() is evaluated each time for each validator for each
field which has one). We noticed this in our production system.

Use a custom lazy_format() object instead which does the formatting
lazily with less overhead.

Using the benchmark attached to the PR (snipped to tottime>100ms):

Before, model serializer:

         9225123 function calls (9200068 primitive calls) in 8.337 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    25000    1.299    0.000    3.534    0.000 functional.py:125(__prepare_class__)
  2415001    0.954    0.000    0.954    0.000 {built-in method builtins.hasattr}
  1350000    0.901    0.000    0.901    0.000 functional.py:145(__promise__)
  1550001    0.521    0.000    0.521    0.000 {built-in method builtins.setattr}
    25000    0.494    0.000    0.735    0.000 {built-in method builtins.__build_class__}
    30000    0.298    0.000    0.385    0.000 fields.py:297(__init__)
    25000    0.289    0.000    5.895    0.000 fields.py:740(__init__)
    25000    0.264    0.000    0.802    0.000 field_mapping.py:66(get_field_kwargs)
    25000    0.241    0.000    0.241    0.000 functional.py:100(__proxy__)
670003/670001    0.203    0.000    0.211    0.000 {built-in method builtins.getattr}
     5000    0.189    0.000    7.722    0.002 serializers.py:990(get_fields)
    25000    0.186    0.000    0.400    0.000 functools.py:186(total_ordering)
    25000    0.158    0.000    0.299    0.000 functional.py:234(wrapper)
     5000    0.129    0.000    0.136    0.000 serializers.py:1066(get_field_names)
    25000    0.104    0.000    1.002    0.000 serializers.py:1195(build_standard_field)

After, model serializer:

         3265096 function calls (3240059 primitive calls) in 2.645 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    30000    0.237    0.000    0.315    0.000 fields.py:295(__init__)
    25000    0.218    0.000    0.639    0.000 field_mapping.py:66(get_field_kwargs)
    25000    0.214    0.000    0.665    0.000 fields.py:743(__init__)
     5000    0.156    0.000    2.086    0.000 serializers.py:988(get_fields)
    25000    0.107    0.000    0.210    0.000 functional.py:234(wrapper)

Before, regular serializer:

         8060003 function calls (7960003 primitive calls) in 7.123 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    25000    1.569    0.000    3.897    0.000 functional.py:125(__prepare_class__)
  1350000    1.013    0.000    1.013    0.000 functional.py:145(__promise__)
  2365000    0.925    0.000    0.925    0.000 {built-in method builtins.hasattr}
  1550000    0.512    0.000    0.512    0.000 {built-in method builtins.setattr}
    25000    0.378    0.000    0.550    0.000 {built-in method builtins.__build_class__}
    25000    0.307    0.000    5.946    0.000 fields.py:740(__init__)
    30000    0.277    0.000    0.360    0.000 fields.py:297(__init__)
80000/5000    0.202    0.000    6.526    0.001 copy.py:132(deepcopy)
    25000    0.172    0.000    0.172    0.000 functional.py:100(__proxy__)
   540000    0.152    0.000    0.152    0.000 {built-in method builtins.getattr}
    25000    0.119    0.000    6.199    0.000 fields.py:604(__deepcopy__)

After, regular serializer:

         2150003 function calls (2050003 primitive calls) in 1.609 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    30000    0.224    0.000    0.293    0.000 fields.py:295(__init__)
    25000    0.181    0.000    0.607    0.000 fields.py:743(__init__)
80000/5000    0.151    0.000    1.074    0.000 copy.py:132(deepcopy)
    25000    0.102    0.000    0.819    0.000 fields.py:607(__deepcopy__)
2019-05-24 14:50:28 +03:00
Ryan P Kilby
19ca86d8d6
Fix lazy translation of ListField errors (#6708)
* Test init for fields w/ lazy translations
* Fix lazy translations for ListField
2019-05-22 19:41:53 -07:00
Florian Wendelborn
0d0e7c3ae0 Add HTTP 308 Permanent Redirect (#6693) 2019-05-22 11:25:12 -07:00
Ryan P Kilby
db37512a6e
Remove 3.10 deprecations (#6687)
* Remove DjangoObjectPermissionsFilter
* Remove detail_route/list_route
* Bump deprecation warning versions
2019-05-21 10:36:55 -07: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
Ryan P Kilby
1b8141a4aa
Fix nullable source='*' fields (#6659) 2019-05-20 14:58:02 -07:00
Rick van Hattem
2c92548963 Made the loading of the fund sidebar async (#6686) 2019-05-20 16:09:23 +01:00
Ran Benita
7232586c7c Simplify Serializer.fields with @cached_property (#6662) 2019-05-20 14:49:47 +01:00
Joachim Jablon
43a9cc1b7a Fix CursorPagination when objects get deleted between calls (#6504) (#6593)
* Added regression tests (#6504)

Co-Authored-By: Tom Quinonero <tq@3yourmind.com>

* Fix CursorPagination when objects get deleted between calls (#6504)

Co-Authored-By: Tom Quinonero <tq@3yourmind.com>
2019-05-20 14:41:31 +01:00
Asif Saif Uddin
ac0f0a1774 Updated optional requirements (#6673) 2019-05-14 10:14:11 -07:00
Ryan P Kilby
c3a13916d2
Update release notes (#6671)
* Add 3.9.4 release notes to master
* Add top-level symlink to release notes
2019-05-14 10:13:14 -07:00
Carlton Gibson
37f210a455
Added OpenAPI Schema Generation. (#6532)
Co-authored-by: Lucidiot <lucidiot@protonmail.com>
Co-authored-by: dongfangtianyu <dongfangtianyu@qq.com>
2019-05-13 16:07:03 +02:00
Asif Saif Uddin
a91e6a0e69 Updated test packges version (#6665) 2019-05-13 09:21:27 +01:00
Ran Benita
9811a29a5a Pass through memo in __deepcopy__ as required by the docs (#6660)
This is needed to avoid problems with recursive loops. See
https://docs.python.org/3.7/library/copy.html
toward the end.
2019-05-09 09:20:32 +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
Tim Gates
564faddb0f Make Markdown 2.6 the minimum compatible version (#6576) 2019-05-08 19:34:38 -07:00
Xavier Ordoquy
2e7ab9d6c6
Merge pull request #6654 from jorrit-wehelp/patch-1
Fix test with STRICT_JSON setting
2019-05-08 18:14:27 +02:00
Jorrit
3a21b390ff
Fix test with STRICT_JSON setting
Test is not overriding the intended setting, should be nested inside settings.REST_FRAMEWORK
2019-05-08 16:48:45 +02:00
Andreu Vallbona Plazas
be5a9f78f3 Added note on serializing extra fields from Through Model (#6652)
* adding small clarification on ManyToManyFields with a Through Model

As pointed here: https://github.com/encode/django-rest-framework/pull/6585#issuecomment-490145334 I suggest to add the small clarification to work with **ManyToManyFields with a Through Model**.

* Remove blank line.
2019-05-07 20:01:24 +02:00
Serkan Hosca
680ed8aa8b Add django-rest-witchcraft to third party packages (#6587) 2019-05-06 16:19:51 -07:00
Asif Saif Uddin
50a24d6d7f Drop Python 3.4 support (#6620) 2019-05-06 11:35:58 -07:00
Aart Goossens
0f819d844d Remove recommendation for DRF Docs (#6580)
Since DRF Docs is not compatible with the latest version of DRF (or Django?; related issue: https://github.com/manosim/django-rest-framework-docs/issues/180) and the latest release is almost 3 years ago I suggest to remove the recommendation for this package.
2019-05-03 15:26:06 -07:00
Jimmy Merrild Krag
14fad0d690 Fix capitalization, markdown syntax link in docs (#6621)
The `Pygments` and `Markdown` python packages have first letter capital.
Fixed link to markdown syntax to go directly to the syntax page.
2019-05-02 18:17:33 -07:00
Jon Dufresne
1e519486e1 Fixup isort command/config (#6639) 2019-05-01 17:42:10 -07:00
Afnarel
67d2eabd6c Fix username in template for custom user models (#6612) 2019-05-01 17:23:23 -07:00
Jon Dufresne
f669395dd8 Fix BytesWarning in test_schemas.py (#6638) 2019-05-01 16:47:01 -07:00
Jon Dufresne
e16273a658 Simplify import_from_string() with Django's import_string() (#6617) 2019-05-01 15:32:28 -07:00
vu3jej
1c976f2ac8 Fix typo in docs (#6628) 2019-05-01 15:24:38 -07:00
Jon Dufresne
059947028b Update docs on django-oauth-toolkit (#6618)
Since django-oauth-toolkit 1.2.0 (2018-06-03), the package requires
Python 3.4+.

https://github.com/jazzband/django-oauth-toolkit/blob/master/CHANGELOG.md#120-2018-06-03
2019-05-01 07:52:26 +02:00
Jon Dufresne
5e1619bc9e Remove unnecessary assignments immediately before a return statement (#6619)
Cleans up the pattern:

    ...
    myvar = <expression>
    return myvar

To:

    ...
    return <expression>
2019-05-01 07:51:54 +02:00
Jon Dufresne
565794bedc Replace virtualenv references with venv in the docs (#6636)
On Python 3, creating virtual environments is available through the
stdlib module venv.

https://docs.python.org/3/library/venv.html
2019-05-01 07:51:02 +02:00
Jon Dufresne
8687f6135f Remove references to Python 2 from the docs (#6635) 2019-05-01 07:50:28 +02:00
Jon Dufresne
3f19e66d9f Replace all usage ugettext functions with the non-u versions (#6634)
On Python 3, the ugettext functions are a simple aliases of their non-u
counterparts (the 'u' represents Python 2 unicode type). Starting with
Django 3.0, the u versions will be deprecated.

https://docs.djangoproject.com/en/dev/releases/3.0/#id2

> django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
> ungettext(), and ungettext_lazy() are deprecated in favor of the
> functions that they’re aliases for:
> django.utils.translation.gettext(), gettext_lazy(), gettext_noop(),
> ngettext(), and ngettext_lazy().
2019-05-01 07:49:54 +02:00
Jon Dufresne
513a49d63b Drop default 'utf-8' to .encode()/.decode() (#6633)
A Python 3 cleanup that allows for less noise in the code.

https://docs.python.org/3/library/stdtypes.html#bytes.decode
https://docs.python.org/3/library/stdtypes.html#str.encode
2019-05-01 07:49:16 +02:00
Jon Dufresne
734ca7ca8c Remove unneeded repo() test (#6632) 2019-05-01 07:46:30 +02:00
Jon Dufresne
b4e80ac721 Remove unnecessary coerce to str() in test_decorators.py (#6637)
Was added only for Python 2 compatibility.
2019-05-01 07:45:16 +02:00
Jon Dufresne
ff86f09f74 Remove unnecessary compatibility shims from rest_framework/compat.py (#6631)
For Python 3, collections.abc.Mapping and collections.abc.MutableMapping
are always available from the stdlib.
2019-05-01 07:44:33 +02: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
Xavier Ordoquy
5c992baf32
Merge pull request #6627 from vu3jej/docs
Correct misspelled class name in validators docs
2019-04-30 14:55:27 +02:00
Jithesh Eriyakkadan Janardhanan
908236a576 Correct misspelled class name 2019-04-30 18:01:17 +05:30
Jon Dufresne
1a0a8dde00 Correct misspelled module 'typing' (#6616)
https://docs.python.org/3/library/typing.html
2019-04-30 09:44:01 +01:00
Carlton Gibson
7f16ed7727 Correct version number in release notes. 2019-04-29 16:35:17 +02:00
Carlton Gibson
83d09c7bc5
Update version and release notes for v3.9.3. 2019-04-29 16:30:44 +02:00
Carlton Gibson
bf9859de51
Adjust django-guardian check for PY2 compatible version. (#6613) 2019-04-29 16:08:39 +02:00
Xavier Ordoquy
59a5a5a868
Merge pull request #6611 from dsanders11/patch-1
Fix typo in docs
2019-04-27 22:04:07 +02:00
David Sanders
95e28b2252
Fix typo in docs 2019-04-27 12:07:49 -07:00
Dmitry Alimov
1ac0f63aa9 Fix private attributes ignore in documentation (#6601) 2019-04-21 17:27:13 +01:00
Xavier Ordoquy
db65282163
Merge pull request #6588 from rawteech/master
Add some words about `extra_kwargs` and explicitly defined fields.
2019-04-15 02:31:07 +02:00
Billy Rotich
f8c4e5079e Minor documentation fixes (#6581) 2019-04-13 15:02:19 +02:00
Asif Saif Uddin
29cbe574a3 Fix DeprecationWarning in tests (#6551) 2019-04-05 14:27:07 -07:00