0003-sql-run-role-migrations-in-sql-mode-67190.patch
tests/test_role.py | ||
---|---|---|
2 | 2 | |
3 | 3 |
from quixote import get_publisher |
4 | 4 | |
5 |
from wcs import sql |
|
5 | 6 |
from wcs.roles import get_user_roles |
6 | 7 | |
7 | 8 |
from .utilities import clean_temporary_pub, create_temporary_pub |
... | ... | |
38 | 39 |
get_publisher().role_class.wipe() |
39 | 40 |
role = get_publisher().role_class(name='Hello world') |
40 | 41 |
role.store() |
41 |
with open(role.get_object_filename(), 'rb') as fd: |
|
42 |
obj = pickle.load(fd)
|
|
43 |
del obj.slug
|
|
44 |
with open(role.get_object_filename(), 'wb') as fd:
|
|
45 |
pickle.dump(obj, fd)
|
|
46 |
with open(role.get_object_filename(), 'rb') as fd:
|
|
47 |
assert pickle.load(fd).slug is None |
|
42 | ||
43 |
conn, cur = sql.get_connection_and_cursor()
|
|
44 |
sql_statement = 'UPDATE roles SET slug = NULL'
|
|
45 |
cur.execute(sql_statement)
|
|
46 |
conn.commit()
|
|
47 |
cur.close()
|
|
48 | ||
48 | 49 |
assert get_publisher().role_class.get(role.id).slug == 'hello-world' |
49 | 50 | |
50 | 51 |
wcs/sql.py | ||
---|---|---|
3264 | 3264 | |
3265 | 3265 |
_numerical_id = False |
3266 | 3266 | |
3267 |
@classmethod |
|
3268 |
def get(cls, id, ignore_errors=False, ignore_migration=False, column=None): |
|
3269 |
o = super().get(id, ignore_errors=ignore_errors, ignore_migration=ignore_migration, column=column) |
|
3270 |
if o and not ignore_migration: |
|
3271 |
if o.migrate(): |
|
3272 |
o.store() |
|
3273 |
return o |
|
3274 | ||
3267 | 3275 |
@guard_postgres |
3268 | 3276 |
def store(self): |
3269 | 3277 |
if self.slug is None: |
3270 |
- |