[Django] #33101: Improve output of non-interactive migration questioner

10 views
Skip to first unread message

Django

unread,
Sep 10, 2021, 7:13:56 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
------------------------------------------------+------------------------
Reporter: Hiroki Sawano | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
The non-interactive questioner doesn't tell anything about a suppressed
prompt, so it is difficult to see what happened when, for example, adding
a non-nullable field to a model without specifying a default.
I'd like it to print messages as shown below, like the interactive
questioner does.

{{{
$ python manage.py makemigrations --noinput
It is impossible to add a non-nullable field '...' to ... without
specifying a default. This is because the database needs something to
populate existing rows.
}}}

If that makes sense, I'll change {{{ask_not_null_addition}}},
{{{ask_not_null_alteration}}}, and {{{ask_auto_now_add_addition}}} in
{{{django.db.migrations.questioner.NonInteractiveMigrationQuestioner}}}
like this:

{{{
class NonInteractiveMigrationQuestioner(MigrationQuestioner):

def ask_not_null_addition(self, field_name, model_name):
# We can't ask the user, so act like the user aborted.
print(
f"It is impossible to add a non-nullable field '{field_name}'
"
f"to {model_name} without specifying a default. This is "
f"because the database needs something to populate existing "
f"rows."
)
sys.exit(3)

def ask_not_null_alteration(self, field_name, model_name):
# We can't ask the user, so set as not provided.
print(
f"It is impossible to change a nullable field '{field_name}' "
f"on {model_name} to non-nullable without providing a "
f"default. This is because the database needs something to "
f"populate existing rows.\n"
f"Existing rows that contain NULL values "
f"will have to be handled manually, for example with a "
f"RunPython or RunSQL operation."
)
return NOT_PROVIDED

def ask_auto_now_add_addition(self, field_name, model_name):
# We can't ask the user, so act like the user aborted.
print(
f"It is impossible to add the field '{field_name}' with "
f"'auto_now_add=True' to {model_name} without providing a "
f"default. This is because the database needs something to "
f"populate existing rows."
)
sys.exit(3)
}}}

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

Django

unread,
Sep 10, 2021, 7:14:58 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
-------------------------------------+-------------------------------------
Reporter: Hiroki Sawano | Owner: Hiroki
Type: | Sawano
Cleanup/optimization | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hiroki Sawano):

* owner: nobody => Hiroki Sawano
* status: new => assigned


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

Django

unread,
Sep 10, 2021, 7:19:00 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
-------------------------------------+-------------------------------------
Reporter: Hiroki Sawano | Owner: Hiroki
Type: | Sawano
Cleanup/optimization | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hiroki Sawano):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:2>

Django

unread,
Sep 10, 2021, 7:26:01 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
-------------------------------------+-------------------------------------
Reporter: Hiroki Sawano | Owner: Hiroki
Type: | Sawano
Cleanup/optimization | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:

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):

* needs_tests: 1 => 0
* easy: 1 => 0


Comment:

Duplicate of #29470.

--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:3>

Django

unread,
Sep 10, 2021, 7:26:06 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
-------------------------------------+-------------------------------------
Reporter: Hiroki Sawano | Owner: Hiroki
Type: | Sawano
Cleanup/optimization | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: duplicate

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: assigned => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:4>

Django

unread,
Sep 10, 2021, 7:38:56 AM9/10/21
to django-...@googlegroups.com
#33101: Improve output of non-interactive migration questioner
-------------------------------------+-------------------------------------
Reporter: Hiroki Sawano | Owner: Hiroki
Type: | Sawano
Cleanup/optimization | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hiroki Sawano):

Replying to [comment:4 Mariusz Felisiak]:
Oh sorry. I couldn't find the duplicated issue. Thank for checking.

--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:5>

Reply all
Reply to author
Forward
0 new messages