The argument of having new specialized bulk_update_cast method is more 
logical than the earlier two approaches. But the best approach should be 
drop using Case / When which will eventually come with #31202 
<https://code.djangoproject.com/ticket/31202> or #29771 
<https://code.djangoproject.com/ticket/29771#ticket>. I wanted to propose 
these solution as a hotfix unless we get #31202 
<https://code.djangoproject.com/ticket/31202> or #29771 
<https://code.djangoproject.com/ticket/29771#ticket> done. As we are going 
to upgrade the bulk_update in near future, resolving the bug for now seems 
reasonable to me.
PS: Currently going through all the discussions for #31202 
<https://code.djangoproject.com/ticket/31202> and #29771 
<https://code.djangoproject.com/ticket/29771#ticket> as there are a lot of 
them, will try to propose a solution soon once the #21961 
<https://code.djangoproject.com/ticket/21961> is closed.

*Regards,*
Akash Kumar Sen

LinkedIn <https://www.linkedin.com/in/akash-kumar-sen-220b651b0/> | GitHub 
<https://github.com/Akash-Kumar-Sen>

On Tuesday, October 17, 2023 at 4:27:50 AM UTC+5:30 charettes wrote:

> Hello Akash,
>
> Another approach that isn't mentioned here but alluded to in the ticket 
> <https://code.djangoproject.com/ticket/33647#comment:4> is to actually 
> move bulk_update away from using Case / When which is the root of the issue 
> here.
>
> We know that using Case / When is slow 
> <https://code.djangoproject.com/ticket/31202> and is the reason why we 
> need to perform casting in the first place 
> <https://github.com/django/django/pull/9606#discussion_r173390105>. While 
> knowing that there is complexity 
> <https://code.djangoproject.com/ticket/33647#comment:5> in doing so we 
> already have pointers on how to approach the problem 
> <https://code.djangoproject.com/ticket/29771> and it was already 
> discussed in the past 
> <https://groups.google.com/g/django-developers/c/jIGj1KKuaDM/m/zZERk0MpAgAJ>
> .
>
> I think that even if it requires a larger investment than adding a new 
> kwarg to Cast or have bulk_update call a new specialized bulk_update_cast 
> method on the backend instead of checking for the 
> requires_casted_case_in_updates 
> flag it should be a strongly considered option.
>
> Cheers,
> Simon
> Le lundi 16 octobre 2023 à 10:17:07 UTC-4, Akash Sen a écrit :
>
>> Ticket#33647 : bulk_update silently truncating values for size limited 
>> fields <https://code.djangoproject.com/ticket/33647>
>>
>> *Approach 1:*
>> As mentioned by Simon in this comment 
>> <https://code.djangoproject.com/ticket/33647#comment:3> we can introduce 
>> a new argument maybe named  generic in the database function Cast similar 
>> to the following
>> Cast(expr, ArrayField(CharField(max_length=20), generic=True).
>> Although as mentioned by Mariusz in this comment 
>> <https://github.com/django/django/pull/17366#issuecomment-1763440668> "we 
>> cannot introduce new keyword arguments into database function that will be 
>> only be used to fix usage elsewhere in the Django code."
>> But the explanation is still a little unclear to me, it would be great if 
>> someone can explain the reason.
>>
>> *Approach 2:*
>> As we will not be able to introduce a new new keyword arguments into 
>> database function we can create a new database function named something 
>> like GenericCast,That will cast according to the type only without 
>> specifying the maximum length.
>> And we will use this to the only line causing this regression in 
>> bulk_update, i.e : 
>> https://github.com/django/django/blob/a1e4e86f923dc8387b0a9c3025bdd5d096a6ebb8/django/db/models/query.py#L765
>>  
>> .
>>
>> I would like to move forward with the Approach 2. Some feedback would be 
>> great.
>>
>

-- 
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/ee2de40e-398c-47b1-ad33-c2be3947c47bn%40googlegroups.com.

Reply via email to