Hi!

I want to implement these changes and I have a PR in the 
ticket https://code.djangoproject.com/ticket/32406
At the moment I have a new `update_returning` method but I can easily 
replace it with ` (updates=None, *, returning:bool=None, **kwargs)` if you 
decide to add functionality to the existing method instead. I did a search 
on github and found only a single project with `returning` as model field.
However the returned value in my implementation is a `QuerySet` and I can 
do `.get()`, `.only()`, `.defer()` and `.values()` or `.values_list()` on 
that. Mainly because my use case is updating and refreshing the model in a 
single database operation. The ticket has more examples. What do you think, 
do you see any issues with this approach?

trešdiena, 2021. gada 12. maijs 15:18:50 UTC+3 Tom Carrick rakstīja:

> Apologies, I had totally forgotten about this, but I'm still interested in 
> working on it, but still not sure about a few things.
>
> I've been thinking about the return value a bit. I can foresee cases where 
> you wouldn't want the id returned.  You might want the user to update 
> something by slug, username, or some other identifier without revealing the 
> IDs. Of course the user could reformat the return value however they like, 
> but I don't see a reason to ask for something that isn't necessary.
>
> So I think a list of some kind of object (namedtuple or dict probably) 
> makes the most sense to me. As for also adding the count, I am not sure. 
> The return value would then be e.g. (1, [<data>]). I'm guessing this count 
> would remain as the number of matched rows, rather than the updated ones - 
> I am not sure if returning only gives back rows that were modified or not, 
> the Postgres docs are at least unclear on this. If they're always going to 
> be the same, I'm not sure there is much reason for returning the count when 
> len(return_value) will do.
>
> I'm also not really sure on the data structure though. Namedtuples make 
> the most sense to me but a dict might be useful for those wanting to shove 
> this directly into JsonResponse, without needing _asdict(), for example.
>
> Cheers,
> Tom
>
> On Wed, 27 Jan 2021 at 10:45, Florian Apolloner <f.apo...@gmail.com> 
> wrote:
>
>> Hi Simon,
>>
>> On Wednesday, January 27, 2021 at 5:54:42 AM UTC+1 charettes wrote:
>>
>>> I think that's the best option here if we want to elegantly add support 
>>> for this feature while maintaining backward compability. Something along 
>>> the lines of ...
>>>
>>
>> That is certainly an interesting approach. It kinda breaks the "there 
>> should be one way of doing things" rule, but…
>>
>> The usage of `returning` bring another set of questions though. Since 
>>> UPDATE are not ordered RETURNING data has little value without the primary 
>>> key associated with the updated rows. Maybe the return value of 
>>> `returning=[f1, ..., fn]` should be a dict mapping the primary key to list 
>>> of returning values.
>>>
>>
>> I am not sure I like that. For things where you update just one row and 
>> want to know the new values the primary key doesn't make much sense. 
>> Granted for multiple rows it would maybe easier to have it automatically 
>> keyed by the pk, but returning something always (the pk) without having an 
>> option to disable  it seems kinda wrong to me. Not sure what the best 
>> option would be.
>>
>> Cheers,
>> Florian
>>
>> -- 
>>
> You received this message because you are subscribed to the Google Groups 
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-develop...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/4eea605a-57d7-4ce3-b233-3eb88c91e110n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/4eea605a-57d7-4ce3-b233-3eb88c91e110n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ee284d47-6181-426d-98fd-3a0e50e0d9abn%40googlegroups.com.

Reply via email to