Repository: rucio/rucio
Issue: Release candidate 1.20.4rc1 is unstable

Motivation
----------
There are issues with the release candidate:
- reaper2: messages fail to serialize
- judge: hangs on some requests
- REST list_replicas: TypeError, keys must be a string

Modification
------------
Reaper2 messages should be external representations.
Judge is hanging as the string type new internaltypes use with the backend db is different. This causes the indexes to be ignored and a query can need to scan the full table. This type needs to be changed from unicode.



Changed files:
lib/rucio/db/sqla/models.py, lib/rucio/daemons/reaper/reaper2.py

diff --git a/lib/rucio/daemons/reaper/reaper2.py b/lib/rucio/daemons/reaper/reaper2.py
index 3bd6638f8..788f016f9 100644
--- a/lib/rucio/daemons/reaper/reaper2.py
+++ b/lib/rucio/daemons/reaper/reaper2.py
@@ -88,7 +88,7 @@ def delete_from_storage(replicas, prot, rse_info, staging_areas, prepend_str):
         for replica in replicas:
             # Physical deletion
             try:
-                deletion_dict = {'scope': replica['scope'],
+                deletion_dict = {'scope': replica['scope'].external,
                                  'name': replica['name'],
                                  'rse': rse_name,
                                  'file-size': replica['bytes'],
@@ -142,7 +142,7 @@ def delete_from_storage(replicas, prot, rse_info, staging_areas, prepend_str):
     except (ServiceUnavailable, RSEAccessDenied, ResourceTemporaryUnavailable) as error:
         for replica in replicas:
             logging.warning('%s Deletion NOACCESS of %s:%s as %s on %s: %s', prepend_str, replica['scope'], replica['name'], replica['pfn'], rse_name, str(error))
-            add_message('deletion-failed', {'scope': replica['scope'],
+            add_message('deletion-failed', {'scope': replica['scope'].external,
                                             'name': replica['name'],
                                             'rse': rse_name,
                                             'file-size': replica['bytes'],
diff --git a/lib/rucio/db/sqla/models.py b/lib/rucio/db/sqla/models.py
index 1b0d519f0..56483382a 100644
--- a/lib/rucio/db/sqla/models.py
+++ b/lib/rucio/db/sqla/models.py
@@ -46,7 +46,9 @@ from rucio.db.sqla.constants import (AccountStatus, AccountType, DIDAvailability
                                      BadPFNStatus)
 from rucio.db.sqla.history import Versioned
 from rucio.db.sqla.session import BASE
-from rucio.db.sqla.types import GUID, BooleanString, JSON, InternalAccountString, InternalScopeString
+from rucio.db.sqla.types import GUID, BooleanString, JSON
+from rucio.db.sqla.types import InternalAccountString as _InternalAccountString
+from rucio.db.sqla.types import InternalScopeString as _InternalScopeString
 
 
 # Recipe to force str instead if unicode
@@ -56,6 +58,16 @@ def String(*arg, **kw):
     return _String(*arg, **kw)
 
 
+def InternalScopeString(*arg, **kw):
+    kw['convert_unicode'] = 'force'
+    return _InternalScopeString(*arg, **kw)
+
+
+def InternalAccountString(*arg, **kw):
+    kw['convert_unicode'] = 'force'
+    return _InternalAccountString(*arg, **kw)
+
+
 @compiles(Boolean, "oracle")
 def compile_binary_oracle(type_, compiler, **kw):
     return "NUMBER(1)"