Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2020-06-30 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  Ahmet DAL|Owner:  Sergey
 |  Fedoseev
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  3.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Sergey Fedoseev):

 * owner:  nobody => Sergey Fedoseev
 * status:  new => assigned


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.778754698079cf83c3ea3048e4f80005%40djangoproject.com.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2019-11-22 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  Ahmet DAL|Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  3.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Baptiste Mispelon):

 * version:  1.8 => 3.0


Comment:

 I was able to reproduce the reported error on the latest master
 (a5855c8f0fe17b7e888bd8137874ef78012a7294) by using the following models:
 {{{
 #!python
 from django.db import models


 class Ticket(models.Model):
 date_opened = models.DateTimeField()


 class Rule(models.Model):
 duration = models.DurationField()


 class Action(models.Model):
 percent = models.FloatField()
 rule = models.ForeignKey('Rule', on_delete=models.CASCADE)


 class Expire(models.Model):
 ticket = models.ForeignKey('Ticket', on_delete=models.CASCADE)
 action = models.ForeignKey('Action', on_delete=models.CASCADE)
 }}}

 And the following testcase:
 {{{
 #!python
 from datetime import timedelta

 from django.db.models import F
 from django.test import TestCase
 from django.utils import timezone

 from .models import Ticket, Rule, Action, Expire


 class TicketTestCase(TestCase):
 def test_ticket(self):
 now = timezone.now()

 ticket1 = Ticket.objects.create(date_opened=now-timedelta(days=6))
 ticket2 = Ticket.objects.create(date_opened=now-timedelta(days=4))

 rule = Rule.objects.create(duration=timedelta(days=10))
 action = Action.objects.create(rule=rule, percent=50)

 expire = Expire.objects.create(ticket=ticket1, action=action)
 expire = Expire.objects.create(ticket=ticket2, action=action)


 qs =
 Expire.objects.filter(ticket__date_opened__lte=(timezone.now() -
 F("action__percent") * F("action__rule__duration") / 100))
 self.assertQuerysetEqual(qs, [ticket1.pk], transform=lambda x:
 x.ticket.pk)
 }}}

 As described in the original ticket, the testcase fails with sqlite
 (`DatabaseError: Invalid connector for timedelta: *.`) but passes when
 using postgresql.

 The proposed solution of adding the new `*` and `/` operators to
 `sqlite3.DatebaseOperations.combine_duration_expression()` [1] only works
 in that the `DatebaseError` disappears but the test still fails because
 the returned queryset is empty.

 Josh's suggestions of wrapping everything in an `ExpressionWrapper` don't
 seem to make a difference either.



 [1]
 
https://github.com/django/django/blob/a5855c8f0fe17b7e888bd8137874ef78012a7294/django/db/backends/sqlite3/operations.py#L315

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.08c1cf15111d06ccbbfcc9b6b9d09e1f%40djangoproject.com.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2019-06-04 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  Ahmet DAL|Owner:  (none)
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Caio Ariede):

 * owner:  Caio Ariede => (none)
 * status:  assigned => new


-- 
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/066.2710614d75bdbbac92f33f2f3f495cc6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2015-08-30 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  javrasya |Owner:
 |  caioariede
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by caioariede):

 It looks like there's an issue with the user-defined function used by the
 SQLite backend to make arithmetic calculations:

 
https://github.com/django/django/blob/master/django/db/backends/sqlite3/base.py#L416

 It only expects microseconds, timedeltas and datetime objects. In the
 given example, it also would need to expect an integer (the percent). This
 works with the PostgreSQL backend but not with the SQLite backend.

--
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/066.4d5c37e7145f848de96da7ac55db89b0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2015-08-28 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  javrasya |Owner:
 |  caioariede
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by jarshwah):

 You may also need an ExpressionWrapper to provide the right hand side
 output type:

 {{{
 expires = Expire.objects.filter(
 ticket__date_opened__lte=
datetime.now() - ExpressionWrapper(
(F("action__percent") * F("action__rule__duration")) / 100,
output_field=FloatField()
)
 )
 }}}

--
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/066.4117e5dd155e1b50a6655fdaf7066923%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2015-08-28 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  javrasya |Owner:
 |  caioariede
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by jarshwah):

 This looks like an order of precedence issue. Durations only support + and
 -, but F() expressions support them all. Try rewriting your query like
 this please?

 {{{
 expires = Expire.objects.filter(
 ticket__date_opened__lte=
datetime.now() - (
(F("action__percent") * F("action__rule__duration")) / 100
)
 )
 }}}

 I've broken up the query over multiple lines to show where the brackets
 should be placed. The query should be `datetime() - ( calculation )`.

--
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/066.935aacc7424056b9094954699d6d8b47%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed.

2015-08-27 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  javrasya |Owner:
 |  caioariede
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by caioariede):

 * status:  new => assigned
 * owner:  nobody => caioariede


--
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/066.faddd1b66f2874e4ef92d2b67fd747ce%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25287: Multiplying and dividing connectors for datetime expressions are not supported by sqlite backed. (was: Multiplying and dividing connectors are not supported by sqlite backed.)

2015-08-18 Thread Django
#25287: Multiplying and dividing connectors for datetime expressions are not
supported by sqlite backed.
-+-
 Reporter:  javrasya |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  sqlite3, | Triage Stage:  Accepted
  combine_duration_expression, F |
  expressions,   |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * type:  Bug => New feature
 * stage:  Unreviewed => Accepted


Comment:

 Feel free to submit a tested patch if you are able.

--
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/066.40e21be8e51fc4496e447b81ed50d1be%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.