diff --git a/tests/test_role.py b/tests/test_role.py index f1121e411..b0d89f05b 100644 --- a/tests/test_role.py +++ b/tests/test_role.py @@ -2,6 +2,7 @@ import pickle from quixote import get_publisher +from wcs import sql from wcs.roles import get_user_roles from .utilities import clean_temporary_pub, create_temporary_pub @@ -38,13 +39,13 @@ def test_migrate(): get_publisher().role_class.wipe() role = get_publisher().role_class(name='Hello world') role.store() - with open(role.get_object_filename(), 'rb') as fd: - obj = pickle.load(fd) - del obj.slug - with open(role.get_object_filename(), 'wb') as fd: - pickle.dump(obj, fd) - with open(role.get_object_filename(), 'rb') as fd: - assert pickle.load(fd).slug is None + + conn, cur = sql.get_connection_and_cursor() + sql_statement = 'UPDATE roles SET slug = NULL' + cur.execute(sql_statement) + conn.commit() + cur.close() + assert get_publisher().role_class.get(role.id).slug == 'hello-world' diff --git a/wcs/sql.py b/wcs/sql.py index 8f2718f23..6d9a611da 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -3264,6 +3264,14 @@ class Role(SqlMixin, wcs.roles.Role): _numerical_id = False + @classmethod + def get(cls, id, ignore_errors=False, ignore_migration=False, column=None): + o = super().get(id, ignore_errors=ignore_errors, ignore_migration=ignore_migration, column=column) + if o and not ignore_migration: + if o.migrate(): + o.store() + return o + @guard_postgres def store(self): if self.slug is None: