[Django] #32759: Use dataclasses to represent models

8 views
Skip to first unread message

Django

unread,
May 18, 2021, 12:59:51 PM5/18/21
to django-...@googlegroups.com
#32759: Use dataclasses to represent models
-------------------------------------+-------------------------------------
Reporter: adsharma | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django documentation and current practice are described in this example:

https://docs.djangoproject.com/en/3.2/intro/tutorial02/#creating-models

This has a number of limitations:

* Python's type checkers don't understand models.CharField and
models.DateTimeField
* They do understand python strings and datetime objects
* There is some activity on typing-sig about teaching them more about
lengths and limits

dataclasses introduced in 3.7 are seeing some adoption.

The same example can be represented as:

https://github.com/adsharma/fquery/pull/2

This is more ergonomic for python programmers trained on dataclasses.

Queries against these dataclasses can be expressed in one of two ways:

* A method chaining API such as:

https://github.com/adsharma/fquery/blob/main/tests/test_operators.py

* SQL via ActiveRecord or DataMapper

https://github.com/adsharma/dataclasses-
sql/blob/master/tests/test_decorators.py

For this to work as well as current django models, two things need to
happen:

* How to pass additional metadata about database schema? (dataclasses
support metadata, perhaps make it more ergonomic?)
* What to do about indices, views and other db concepts

One school of thought is to use SQL DDL.

Some conversation on this topic here:

https://twitter.com/arundsharma/status/1390898932713066499

Would love to hear more from the django community on the topic.

--
Ticket URL: <https://code.djangoproject.com/ticket/32759>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 18, 2021, 2:19:27 PM5/18/21
to django-...@googlegroups.com
#32759: Use dataclasses to represent models
-------------------------------------+-------------------------------------
Reporter: adsharma | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for the proposition, however I don't think it needs to be built-in
into Django it sounds like a third-party package is the best way to
proceed.

By the way, you'll reach a wider audience if you write to the
DevelopersMailingList about your ideas, see
[https://docs.djangoproject.com/en/3.2/internals/contributing/bugs-and-
features/#requesting-features Requesting features].

--
Ticket URL: <https://code.djangoproject.com/ticket/32759#comment:1>

Reply all
Reply to author
Forward
0 new messages