You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Disable `thread_sensitive` where it's not needed
- Perform queries and mutations using async
- `use_query` now supports async functions.
- `use_mutation` now supports async functions.
- `django_idom.types.QueryOptions.thread_sensitive` option to customize how sync queries are executed.
- `django_idom.hooks.use_mutation` now accepts `django_idom.types.MutationOptions` option to customize how mutations are executed.
- Use Python's arg/kwarg handlers to properly interpret and differentiate between `kwarg` and `args`. This allow things such as `query=my_function` to be properly handled.
- The `mutate` argument on `django_idom.hooks.use_mutation` has been renamed to `mutation`.
- Add tests for our database routing feature
- Reduce runtime for tests from ~181 seconds to ~11 seconds by only starting the Django server once
- Fix bug where ReactPy utilizes Django's default cache timeout, which can prematurely expire our cache entries.
Copy file name to clipboardExpand all lines: docs/src/features/hooks.md
+34-4
Original file line number
Diff line number
Diff line change
@@ -57,13 +57,29 @@ The function you provide into this hook must return either a `Model` or `QuerySe
57
57
{% include "../../python/use-query-args.py" %}
58
58
```
59
59
60
-
??? question "Why does the example `get_items`function return `TodoItem.objects.all()`?"
60
+
??? question "Why does `get_items`in the example return `TodoItem.objects.all()`?"
61
61
62
62
This was a technical design decision to based on [Apollo's `useQuery` hook](https://www.apollographql.com/docs/react/data/queries/), but ultimately helps avoid Django's `SynchronousOnlyOperation` exceptions.
63
63
64
64
The `use_query` hook ensures the provided `Model` or `QuerySet` executes all [deferred](https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_deferred_fields)/[lazy queries](https://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are-lazy) safely prior to reaching your components.
65
65
66
-
??? question "Can this hook be used for things other than the Django ORM?"
66
+
??? question "How can I use `QueryOptions` to customize fetching behavior?"
67
+
68
+
<font size="4">**`thread_sensitive`**</font>
69
+
70
+
Whether to run your synchronous query function in thread-sensitive mode. Thread-sensitive mode is turned on by default due to Django ORM limitations. See Django's [`sync_to_async` docs](https://docs.djangoproject.com/en/dev/topics/async/#sync-to-async) docs for more information.
71
+
72
+
This setting only applies to sync query functions, and will be ignored for async functions.
73
+
74
+
=== "components.py"
75
+
76
+
```python
77
+
{% include "../../python/use-query-thread-sensitive.py" %}
@@ -72,7 +88,7 @@ The function you provide into this hook must return either a `Model` or `QuerySe
72
88
1. Want to use this hook to defer IO intensive tasks to be computed in the background
73
89
2. Want to to utilize `use_query` with a different ORM
74
90
75
-
... then you can disable all postprocessing behavior by modifying the `QueryOptions.postprocessor` parameter. In the example below, we will set the `postprocessor` to `None` to disable postprocessing behavior.
91
+
... then you can either set a custom `postprocessor`, or disable all postprocessing behavior by modifying the `QueryOptions.postprocessor` parameter. In the example below, we will set the `postprocessor` to `None` to disable postprocessing behavior.
76
92
77
93
=== "components.py"
78
94
@@ -92,7 +108,9 @@ The function you provide into this hook must return either a `Model` or `QuerySe
92
108
{% include "../../python/use-query-postprocessor-change.py" %}
93
109
```
94
110
95
-
??? question "How can I prevent this hook from recursively fetching `ManyToMany` fields or `ForeignKey` relationships?"
@@ -108,6 +126,18 @@ The function you provide into this hook must return either a `Model` or `QuerySe
108
126
109
127
_Note: In Django's ORM design, the field name to access foreign keys is [postfixed with `_set`](https://docs.djangoproject.com/en/dev/topics/db/examples/many_to_one/) by default._
110
128
129
+
??? question "Can I define async query functions?"
130
+
131
+
Async functions are supported by `use_query`. You can use them in the same way as a sync query function.
132
+
133
+
However, be mindful of Django async ORM restrictions.
134
+
135
+
=== "components.py"
136
+
137
+
```python
138
+
{% include "../../python/use-query-async.py" %}
139
+
```
140
+
111
141
??? question "Can I make ORM calls without hooks?"
Copy file name to clipboardExpand all lines: docs/src/get-started/register-view.md
+1-3
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
---
8
8
9
-
## Render Your View
9
+
## Register a View
10
10
11
11
We will assume you have [created a Django View](https://docs.djangoproject.com/en/dev/intro/tutorial01/#write-your-first-view) before, but here's a simple example below.
12
12
@@ -28,8 +28,6 @@ We will add this new view into your [`urls.py`](https://docs.djangoproject.com/e
28
28
{% include "../../python/example/urls.py" %}
29
29
```
30
30
31
-
Now, navigate to `http://127.0.0.1:8000/example/`. If you copy-pasted the component from the previous example, you will now see your component display "Hello World".
32
-
33
31
??? question "Which urls.py do I add my views to?"
34
32
35
33
For simple **Django projects**, you can easily add all of your views directly into the **Django project's** `urls.py`. However, as you start increase your project's complexity you might end up with way too much within one file.
To test your new Django view, run the following command to start up a development webserver.
12
+
13
+
```bash linenums="0"
14
+
python manage.py runserver
15
+
```
16
+
17
+
Now you can navigate to your **Django project** URL that contains an ReactPy component, such as `http://127.0.0.1:8000/example/` (_from the previous step_).
18
+
19
+
If you copy-pasted our example component, you will now see your component display "Hello World".
20
+
21
+
??? warning "Do not use `manage.py runserver` for production."
22
+
23
+
The webserver contained within `manage.py runserver` is only intended for development and testing purposes. For production deployments make sure to read [Django's documentation](https://docs.djangoproject.com/en/dev/howto/deployment/).
0 commit comments