During deep debuging i found that simple .get triggers FOUR queries:
kwargs['context']['user'] = models.Person.objects.get(
pk=16879
)
And postgresql.log prints this:
2024-05-08 10:21:07.913 CEST [3987190] party@partytest LOG: statement: SELECT "structure_persondata"."id", "structure_persondata"."created_at", "structure_persondata"."updated_at", "structure_persondata"."person_id", "structure_persondata"."first_name", "structure_persondata"."middle_name", "structure_persondata"."last_name", "structure_persondata"."pesel", "structure_persondata"."validity_range" FROM "structure_persondata" WHERE ("structure_persondata"."person_id" = 16879 AND "structure_persondata"."validity_range" @> ('2024-05-08T08:21:05.002321+00:00'::timestamptz)::timestamp with time zone) ORDER BY "structure_persondata"."id" ASC LIMIT 1
2024-05-08 10:21:07.927 CEST [3987190] party@partytest LOG: statement: SELECT "structure_persondata"."id", "structure_persondata"."created_at", "structure_persondata"."updated_at", "structure_persondata"."person_id", "structure_persondata"."first_name", "structure_persondata"."middle_name", "structure_persondata"."last_name", "structure_persondata"."pesel", "structure_persondata"."validity_range" FROM "structure_persondata" WHERE ("structure_persondata"."person_id" = 16879 AND "structure_persondata"."validity_range" @> ('2024-05-08T08:21:05.002321+00:00'::timestamptz)::timestamp with time zone) ORDER BY "structure_persondata"."id" ASC LIMIT 1
2024-05-08 10:21:07.937 CEST [3987190] party@partytest LOG: statement: SELECT "structure_persondata"."id", "structure_persondata"."created_at", "structure_persondata"."updated_at", "structure_persondata"."person_id", "structure_persondata"."first_name", "structure_persondata"."middle_name", "structure_persondata"."last_name", "structure_persondata"."pesel", "structure_persondata"."validity_range" FROM "structure_persondata" WHERE ("structure_persondata"."person_id" = 16879 AND "structure_persondata"."validity_range" @> ('2024-05-08T08:21:05.002321+00:00'::timestamptz)::timestamp with time zone) ORDER BY "structure_persondata"."id" ASC LIMIT 1
2024-05-08 10:21:07.946 CEST [3987190] party@partytest LOG: statement: SELECT "structure_persondata"."id", "structure_persondata"."created_at", "structure_persondata"."updated_at", "structure_persondata"."person_id", "structure_persondata"."first_name", "structure_persondata"."middle_name", "structure_persondata"."last_name", "structure_persondata"."pesel", "structure_persondata"."validity_range" FROM "structure_persondata" WHERE ("structure_persondata"."person_id" = 16879 AND "structure_persondata"."validity_range" @> ('2024-05-08T08:21:05.002321+00:00'::timestamptz)::timestamp with time zone) ORDER BY "structure_persondata"."id" ASC LIMIT 1
I thought, that this code is in some loop, but I did this:
# raise ValueError('before')
kwargs['context']['user'] = models.Person.objects.get(
pk=16879
)
raise ValueError('after')
first I run this with raise before, and no queries at all, than i commented it out, and see 4 queries….
It isn’t problem of postgresql log i suppose, because earlier decorator login_required also triggers queries, and that each queries are once logged.