Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-16 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  Sarah
 |  Boyce
 Type:  New feature  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  fixed
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * status:  assigned => closed
 * resolution:   => fixed


-- 
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/01070185b99ee2fa-aa854c42-9c96-42d1-9d6a-65b9e09bd2dd-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-16 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  Sarah
 |  Boyce
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Mariusz Felisiak ):

 In [changeset:"05bcd5baafc0a5783923e32d2b7e2b7fff7d152a" 05bcd5ba]:
 {{{
 #!CommitTicketReference repository=""
 revision="05bcd5baafc0a5783923e32d2b7e2b7fff7d152a"
 Refs #30129 -- Added test for create() with F() expression in Subquery.

 Fixed in 35431298226165986ad07e91f9d3aca721ff38ec.
 }}}

-- 
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/01070185b99e10a2-c86a07a9-077f-4c6e-aaf4-1ba62363422e-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-15 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  Sarah
 |  Boyce
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Sarah Boyce):

 Thank you Tim! Updated the commit message to credit 

-- 
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/01070185b50885fc-1019df79-da48-4a09-b0ca-55b239a36732-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-14 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  Sarah
 |  Boyce
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Tim Graham):

 I did a bisect and confirmed this was fixed in Django 3.0 by
 35431298226165986ad07e91f9d3aca721ff38ec.

-- 
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/01070185b32e8f4a-f2cf5222-2b86-41fc-bffa-7cf60b140e8f-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-14 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  Sarah
 |  Boyce
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Sarah Boyce):

 * owner:  (none) => Sarah Boyce
 * status:  new => assigned
 * has_patch:  0 => 1


-- 
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/01070185b2437146-948cd06f-ae2a-4978-86f8-f4d0f65816da-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2023-01-14 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  (none)
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Sarah Boyce):

 I think this is resolved (I'm not sure when), raised a PR just to show
 that I think it's been fixed https://github.com/django/django/pull/16451
 (but I will close the PR later).
 I feel like I'm not supposed to close tickets so I'll let a DSF team
 member check I haven't missed anything and close the ticket.

-- 
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/01070185b08edab5-8355886a-cfe5-4ce1-8f5d-39cc785fef4a-00%40eu-central-1.amazonses.com.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2019-03-22 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  (none)
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by birthdaysgift):

 * owner:  birthdaysgift => (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/068.50a1db6456b9d4c00ef107bcf4a00881%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2019-03-20 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:
 |  birthdaysgift
 Type:  New feature  |   Status:  assigned
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by birthdaysgift):

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


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


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2019-01-28 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:  Accepted
  Expressions|
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Tim Graham):

 * stage:  Unreviewed => Accepted


Comment:

 It seems okay, if it's feasible to implement.

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


Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions

2019-01-24 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:
  Expressions|  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Description changed by Charlie McBride:

Old description:

> I understand why F() expressions are generally disallowed inside insert
> statements, the columns you are referencing don't yet exist, so it
> wouldn't make any sense to do so. However, if you are performing an
> insert with a Subquery (as in the example below), it's possible to have
> otherwise valid statements rejected because of the blanket blacklist of
> F() expressions during inserts.
>
> For example:
>
> given the following models:
>

> {{{
> class Item(models.Model):
> pass
>
> class ItemVersion(models.Model):
> item = models.ForeignKey(Item, related_name='versions')
> version_number = models.IntegerField(default=0)
>
> class Meta:
> unique_together = ('item', 'version_number',)
> }}}
>
> I would like to be able to do the following operation to mitigate race
> conditions as described here
> (https://docs.djangoproject.com/en/2.1/ref/models/expressions/#avoiding-
> race-conditions-using-f)
>

>
> {{{
> item = Item.objects.create()
> # arbitrary number of other items created/destroyed etc
> item_version_2 = ItemVersion.objects.create(
> item=item,
> version_number=Subquery(
> item.versions.order_by('- version_number').annotate(
> max_version_number=Coalesce(Max('version_number'), 0)
> ).annotate(
> new_version_number=F('max_version_number) + 1
> ).values('new_version_number')[:1]
>  )
>  )
> }}}
>
> As written, I would expect the F() in the inner expression to always be
> resolvable, because it is in a Subquery (and not the result of an
> insert). However this query is blocked by the compiler because "F()
> expressions can only be used to update, not to insert." Would it be
> possible to allow F expressions in a Subquery even if it is being used in
> an insert? Is there an edge case that I'm missing that caused the team to
> not consider this?

New description:

 I understand why F() expressions are generally disallowed inside insert
 statements, the columns you are referencing don't yet exist, so it
 wouldn't make any sense to do so. However, if you are performing an insert
 with a Subquery (as in the example below), it's possible to have otherwise
 valid statements rejected because of the blanket blacklist of F()
 expressions during inserts.

 For example:

 given the following models:


 {{{
 class Item(models.Model):
 pass

 class ItemVersion(models.Model):
 item = models.ForeignKey(Item, related_name='versions')
 version_number = models.IntegerField(default=0)

 class Meta:
 unique_together = ('item', 'version_number',)
 }}}

 I would like to be able to do the following operation to mitigate race
 conditions as described here
 (https://docs.djangoproject.com/en/2.1/ref/models/expressions/#avoiding-
 race-conditions-using-f)



 {{{
 item = Item.objects.create()
 # arbitrary number of other items created/destroyed etc
 item_version_2 = ItemVersion.objects.create(
 item=item,
 version_number=Subquery(
 item.versions.order_by('-version_number').annotate(
 max_version_number=Coalesce(Max('version_number'), 0)
 ).annotate(
 new_version_number=F('max_version_number) + 1
 ).values('new_version_number')
  )
  )
 }}}

 As written, I would expect the F() in the inner expression to always be
 resolvable, because it is in a Subquery (and not the result of an insert).
 However this query is blocked by the compiler because "F() expressions can
 only be used to update, not to insert." Would it be possible to allow F
 expressions in a Subquery even if it is being used in an insert? Is there
 an edge case that I'm missing that caused the team to not consider this?

--

-- 
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.

Re: [Django] #30129: Allow creating models with fields values as a Subquery() with F() expressions (was: Request to Allow F() Expressions in Subquery() on Insert)

2019-01-24 Thread Django
#30129: Allow creating models with fields values as a Subquery() with F()
expressions
-+-
 Reporter:  Charlie McBride  |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  Subquery, F, Query   | Triage Stage:
  Expressions|  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Tim Graham):

 * easy:  1 => 0


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