Another thread may be switched to between the dmap.pop(fqn) instruction
and the dmap[scls] one, typically at program startup when multiple
threads are making their "first" queries.
Close #1230
Current release
---------------
+Psycopg 3.3.2
+^^^^^^^^^^^^^
+
+Fix race condition in adapters at startup (:ticket:`#1230`).
+
+
Psycopg 3.3.1
^^^^^^^^^^^^^
# If the adapter is not found, look for its name as a string
fqn = scls.__module__ + "." + scls.__qualname__
- if fqn in dmap:
+ if (d := dmap.get(fqn)) is not None:
# Replace the class name with the class itself
- d = dmap[scls] = dmap.pop(fqn)
+ dmap[scls] = d
+ dmap.pop(fqn, None)
return d
format = PyFormat(format)