On a Django 3.2 installation, I am trying to pass a 
stringified integer-only zip code as the key_name argument to KeyTransform:

>>> stats_qs = stats.annotate(municipality_stats=KeyTransform("66049", 
"data")).values("municipality_stats")
<QuerySet [{'municipality_stats': *None*}]>

As highlighted above, it fails to work. The reason, as you can see in bold 
below, is that the key is being interpolated as an integer in the resulting 
query:

>>> str(stats_qs.query)
'SELECT ("datasets_stats"."data" -> *66049*) AS "municipality_stats" FROM 
"datasets_stats" WHERE "datasets_stats"."stats_type" = 
totals_municipalities LIMIT 1'

This seems like a bug to me, as a JSON object is not allowed to have an int 
key, though - only str.

Has anyone successfully managed to make this work?

-- 
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/102f7e4d-d189-4352-acd5-4590042365ban%40googlegroups.com.

Reply via email to