Re: [Django] #28980: Make the autodetector validate the type of one-off default values

2018-07-01 Thread Django
#28980: Make the autodetector validate the type of one-off default values
--+
 Reporter:  Nikos Katsos  |Owner:  Jeff
 Type:  Cleanup/optimization  |   Status:  assigned
Component:  Migrations|  Version:  2.0
 Severity:  Normal|   Resolution:
 Keywords:| Triage Stage:  Accepted
Has patch:  0 |  Needs documentation:  0
  Needs tests:  0 |  Patch needs improvement:  0
Easy pickings:  0 |UI/UX:  0
--+

Comment (by Jeff):

 If anyone is willing to give me a hand, I am close to a viable patch, see
 
[https://github.com/jeffyancey/django/commit/a6b9ee29e06ae10c8eda58a21485ad833a241adc
 commit], however I am currently wrangling with an existing test
 `tests/migrations/test_commands.py` -
 `MakeMigrationsTests.test_makemigrations_auto_now_add_interactive`. The
 test is failing like so:

 {{{
 ==
 ERROR: test_makemigrations_auto_now_add_interactive
 (migrations.test_commands.MakeMigrationsTests)
 --
 Traceback (most recent call last):
   File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
 yield
   File "/usr/lib/python3.6/unittest/case.py", line 605, in run
 testMethod()
   File "/usr/lib/python3.6/unittest/mock.py", line 1179, in patched
 return func(*args, **keywargs)
   File "/home/jy/Django/forks/django-
 repo/tests/migrations/test_commands.py", line 1300, in
 test_makemigrations_auto_now_add_interactive
 call_command('makemigrations', 'migrations', interactive=True,
 stdout=out)
   File "/home/jy/Django/forks/django-
 repo/django/core/management/__init__.py", line 148, in call_command
 return command.execute(*args, **defaults)
   File "/home/jy/Django/forks/django-repo/django/core/management/base.py",
 line 354, in execute
 output = self.handle(*args, **options)
   File "/home/jy/Django/forks/django-repo/django/core/management/base.py",
 line 83, in wrapped
 res = handle_func(*args, **kwargs)
   File "/home/jy/Django/forks/django-
 repo/django/core/management/commands/makemigrations.py", line 161, in
 handle
 migration_name=self.migration_name,
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/autodetector.py", line 44, in changes
 changes = self._detect_changes(convert_apps, graph)
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/autodetector.py", line 183, in _detect_changes
 self.generate_added_fields()
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/autodetector.py", line 835, in
 generate_added_fields
 self._generate_added_field(app_label, model_name, field_name)
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/autodetector.py", line 854, in
 _generate_added_field
 field.default = self.questioner.ask_auto_now_add_addition(field,
 model_name)
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/questioner.py", line 224, in
 ask_auto_now_add_addition
 return self._ask_default(field_instance, default='timezone.now')
   File "/home/jy/Django/forks/django-
 repo/django/db/migrations/questioner.py", line 139, in _ask_default
 if field_instance.to_python(code):
   File "/home/jy/Django/forks/django-
 repo/django/db/models/fields/__init__.py", line 1369, in to_python
 parsed = parse_datetime(value)
   File "/home/jy/Django/forks/django-repo/django/utils/dateparse.py", line
 106, in parse_datetime
 match = datetime_re.match(value)
 TypeError: expected string or bytes-like object
 }}}

 I have confirmed that at this point the value being passed to `to_python`
 is the integer 1, which should indeed be an invalid default/one-off value
 to pass for a DateTime field.

 At the moment what seems to be blocking me, I believe, is figuring out how
 `unittest.mock.patch()` works, and how that value is being set for the
 interactive test:

 {{{
 @mock.patch('builtins.input', return_value='1')
 @mock.patch('django.db.migrations.questioner.sys.stdin',
 mock.MagicMock(encoding=sys.getdefaultencoding()))
 def test_makemigrations_auto_now_add_interactive(self, *args):
 """
 makemigrations prompts the user when adding auto_now_add to an
 existing
 model.
 """
 class Entry(models.Model):
 title = models.CharField(max_length=255)
 creation_date = models.DateTimeField(auto_now_add=True)

 class Meta:
 app_label = 'migrations'

 # Monkeypatch interactive questioner to auto accept
 with mock.patch('django.db.migrations.questioner.sys.stdout',
 new_callable=io.StringIO) as prompt_stdout:
 

Re: [Django] #29379: Add autocomplete attribute to contrib.auth fields

2018-07-01 Thread Django
#29379: Add autocomplete attribute to contrib.auth fields
--+
 Reporter:  CHI Cheng |Owner:  nobody
 Type:  New feature   |   Status:  new
Component:  contrib.auth  |  Version:  master
 Severity:  Normal|   Resolution:
 Keywords:| Triage Stage:  Accepted
Has patch:  1 |  Needs documentation:  0
  Needs tests:  0 |  Patch needs improvement:  1
Easy pickings:  0 |UI/UX:  0
--+
Changes (by Jeff):

 * cc: Jeff (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.1afe3cac950431727c0f9b56f22b7d93%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #29540: Project specific default app template

2018-07-01 Thread Django
#29540: Project specific default app template
-+-
   Reporter:  Nathan |  Owner:  nobody
  Gaberel|
   Type:  New| Status:  new
  feature|
  Component:  Core   |Version:  2.0
  (Management commands)  |   Keywords:  app_template,
   Severity:  Normal |  default, settings
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 **Context:** We use custom project and app templates at my company.

 **Problem:** Having to pass a `--template https://...` argument every time
 we use `./manage.py startapp`:
 - developers are likely to forget the argument (and waste time re-setting
 up what was in the template)
 - when they don't, having to lookup the correct url is a pain.

 **Suggestion:**
 - Ideally we could define a default app template once for a project and
 every following call to `./manage.py startapp` would use that template.
 - Having looked at the code, I think he'd be possible to add a
 `DEFAULT_APP_TEMPLATE` setting which could be used as the default case in
 `TemplateCommand.handle_template`
 
(https://github.com/django/django/blob/master/django/core/management/templates.py#L187).
 - It would default to the current app template default in
 `django/conf/app_template` (no breaking change).
 - I could add:
   {{{#!python
   DEFAULT_APP_TEMPLATE = "https://github.com/xxx/yyy/archive/master.zip";
   }}}
   to my `settings.py` to change the default app template for the current
 project.

 If this is accepted, I'd happy to send a PR.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.c626d4e761ad529f0cfc51aa08155aaf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29539: Cannot use Aggregation function in Model.Meta.ordering

2018-07-01 Thread Django
#29539: Cannot use Aggregation function in Model.Meta.ordering
-+-
 Reporter:  wilhelmhb|Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Uncategorized|  Version:  2.0
 Severity:  Normal   |   Resolution:
 Keywords:  ordering, query  | Triage Stage:
  expression, aggregation function   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by wilhelmhb):

 * cc: wilhelmhb (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.cddea303fadce0e500423fe1ca2e333d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #29539: Cannot use Aggregation function in Model.Meta.ordering

2018-07-01 Thread Django
#29539: Cannot use Aggregation function in Model.Meta.ordering
-+-
   Reporter:  wilhelmhb  |  Owner:  nobody
   Type:  Bug| Status:  new
  Component: |Version:  2.0
  Uncategorized  |   Keywords:  ordering, query
   Severity:  Normal |  expression, aggregation function
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 Modifying the example from
 [https://docs.djangoproject.com/en/2.0/topics/db/queries/#] to add
 ordering:
 {{{
 from django.db import models

 class Author(models.Model):
 name = models.CharField(max_length=200)

 class Entry(models.Model):
 headline = models.CharField(max_length=255)
 authors = models.ManyToManyField(Author)

 def __str__(self):
 return self.headline

 class Meta:
 ordering = [
 models.Min('authors__id').asc(),
 models.Max('authors__id').asc()
 ]
 }}}

 The query to get entries will fail with a {{{ProgrammingError}}}: the SQL
 query doesn't contain the {{{GROUP BY}}} clause.
 As aggregation functions are QueryExpression objects, and the ordering
 field handles QueryExpressions since Django 2.0, it should work.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.6ba809099e8366f6f7a004e2fab3f2a0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29500: SQLite functions crashes on NULL values

2018-07-01 Thread Django
#29500: SQLite functions crashes on NULL values
-+-
 Reporter:  Sergey Fedoseev  |Owner:  Srinivas
 |  Reddy Thatiparthy
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  2.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Nick Pope):

 We need to be careful how we handle this to ensure that the behaviour
 mirrors other backends.

 I've checked PostgreSQL and when any one of the arguments to `POWER()`.
 `LPAD()` or `RPAD()` is `NULL` they return `NULL`.
 We should ensure that we check whether any one of the arguments is `None`
 and, if so, return `None`.

 We must not catch exceptions such as `TypeError` or `ValueError` to do
 this as has been done in the initial version of the
 [https://github.com/django/django/pull/10121 PR].
 If we were to pass a string to `_sqlite_power()` we would expect a
 `TypeError` which should blow up, not return `None`. Compare to
 PostgreSQL:
 {{{
 postgres=# select power(2, 'abc');
 ERROR:  invalid input syntax for type double precision: "abc"
 LINE 1: select power(2, 'abc');
 ^
 }}}
 The second part of the problem here is that the sqlite backend suppresses
 the error message and returns a different exception:
 {{{
 OperationalError: user-defined function raised exception
 }}}
 Obviously this is not particularly helpful, but a quick search and I found
 the following on Stack Overflow: https://stackoverflow.com/a/45834923
 It points to the documentation for
 
[https://docs.python.org/3/library/sqlite3.html#sqlite3.enable_callback_tracebacks
 sqlite3.enable_callback_tracebacks()].

 I would recommend the following:

 1. Creation of a decorator to check for `None` passed into any of the
 arguments which returns `None` or calls the function as appropriate.
 2. Enabling callbacks on tracebacks for sqlite3 (always / when debug
 enabled / documentation change to give instruction).

 Note that the outcome of this pull request will affect
 [https://github.com/django/django/pull/9622 PR/9622] which I am reviewing,
 particular with respect to my
 [https://github.com/django/django/pull/9622#discussion_r165360894
 comment].

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.c9bbbdb14e946e7b83c543e2211fecab%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29538: QueryExpression in ordering of a related object fails

2018-07-01 Thread Django
#29538: QueryExpression in ordering of a related object fails
-+-
 Reporter:  wilhelmhb|Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  2.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  ordering, query  | Triage Stage:
  expression, related object |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by wilhelmhb):

 * cc: wilhelmhb (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.6e656d526a5069490a9acb9b941c70bc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #29538: QueryExpression in ordering of a related object fails

2018-07-01 Thread Django
#29538: QueryExpression in ordering of a related object fails
-+-
   Reporter:  wilhelmhb  |  Owner:  nobody
   Type:  Bug| Status:  new
  Component:  Database   |Version:  2.0
  layer (models, ORM)|   Keywords:  ordering, query
   Severity:  Normal |  expression, related object
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 Since 2.0, according to the doc
 ([https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering]), we
 can use QueryExpression objects in the Model.Meta.ordering field.
 Using:

 {{{
 from django.db import models

 class Musician(models.Model):
 first_name = models.CharField(max_length=50)
 last_name = models.CharField(max_length=50)
 instrument = models.CharField(max_length=100, null=True, blank=True)

 class Meta:
 ordering = [models.F('instrument').asc(null_last=True)]

 class Album(models.Model):
 artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
 name = models.CharField(max_length=100)
 release_date = models.DateField()
 num_stars = models.IntegerField()

 class Meta:
 ordering = ['artist']
 }}}
 fails with {{{ TypeError: 'OrderBy' does not support indexing }}}

 When reaching
 
[https://github.com/django/django/blob/master/django/db/models/sql/compiler.py#L669],
 the compiler tries to use the related model, but at line 679, {{{item}}}
 can be an OrderBy object. Thus the failure.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.bf8241c5a64c306986c8df3cc18ec6d9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29530: Chaining .annotate() on models generates wrong SQL aliases.

2018-07-01 Thread Django
#29530: Chaining .annotate() on models generates wrong SQL aliases.
-+-
 Reporter:  Volodymyr|Owner:  felixxm
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  2.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  annotate, INNER  | Triage Stage:  Accepted
  JOIN, model,   |
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by felixxm):

 * has_patch:  0 => 1


Comment:

 [https://github.com/django/django/pull/10113 PR]

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.a8162ff1978121f7394f17c7b585394d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29408: Add validation of ordering by a field from related model.

2018-07-01 Thread Django
#29408: Add validation of ordering by a field from related model.
-+-
 Reporter:  Shadi Akiki  |Owner:  nobody
 Type:   |   Status:  new
  Cleanup/optimization   |
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Jeff):

 * cc: Jeff (added)


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.84450db76e9c3df0cf698ef3138c8b24%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.