[Django] #33536: Running help() against django.db.models.PositiveIntegerField results in error

6 views
Skip to first unread message

Django

unread,
Feb 22, 2022, 12:25:05 PM2/22/22
to django-...@googlegroups.com
#33536: Running help() against django.db.models.PositiveIntegerField results in
error
-----------------------------------------+------------------------
Reporter: Brenden Hyde | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
**Issue Description:**

As a Django user, I would like to read built-in docstrings for Django
classes without having an existing Django project.

When creating a new Django project, it can be helpful to read the built-in
docstrings for each class in a package before beginning. For example, if I
have never used django.db.models.PositiveIntegerField and want to know
what the "null" or "blank" kwargs do, I can open a Python or IPython REPL
and type the following:

{{{
from django.db import models
help(models.PositiveIntegerField)
}}}

The above, in theory, should print the help doc for the
PositiveIntegerField class. However, the current state of things causes a
traceback instead:

{{{
ImproperlyConfigured: Requested setting USE_I18N, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.
}}}

According to the Django
[https://docs.djangoproject.com/en/4.0/topics/settings/#envvar-
DJANGO_SETTINGS_MODULE/ docs], this issue is caused by not telling Django
where your settings come from. However, if a user is just trying to read
generic documentation for a given class, I don't think they should have to
implement a concrete settings file first. Ideally, a user should be able
to read these docs locally without creating anything at all. I realize
that online documentation through the Django website is available, but it
would be nice to be able to read the docstrings in a REPL.


**Steps to Reproduce**
1. Create a new virtual environment (I use pipenv, but any should work)
2. Install django~=4.0.0 and ipython to your virtualenv
3. open the ipython REPL by running "ipython" from the command line
4. In the REPL, run the following 2 lines of code:

{{{
from django.db import models
help(models.PositiveIntegerField)
}}}
5. The above should result in a traceback ending with this error message:

{{{
ImproperlyConfigured: Requested setting USE_I18N, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.
}}}

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

Django

unread,
Feb 22, 2022, 6:33:52 PM2/22/22
to django-...@googlegroups.com
#33536: Running help() against django.db.models.PositiveIntegerField results in
error
-------------------------------------+-------------------------------------

Reporter: Brenden Hyde | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.0
(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 Tim Graham):

* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for the feedback. This is caused by translatable class attributes
like `description = _("Positive integer")` which access the setting. I
don't see a feasible solution, but these classes don't have docstrings
anyway.

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

Reply all
Reply to author
Forward
0 new messages