Coverage for src/backend/InvenTree/users/migrations/0011_auto_20240523_1640.py: 85%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1# Generated by Django 4.2.12 on 2024-05-23 16:40 

2 

3import structlog 

4 

5from importlib import import_module 

6 

7from django.conf import settings 

8from django.db import migrations 

9 

10 

11logger = structlog.getLogger('inventree') 

12 

13 

14def clear_sessions(apps, schema_editor): # pragma: no cover 

15 """Clear all user sessions.""" 

16 

17 # Ignore in test mode 

18 if settings.TESTING: 18 ↛ 19line 18 didn't jump to line 19 because the condition on line 18 was never true

19 return 

20 

21 try: 

22 engine = import_module(settings.SESSION_ENGINE) 

23 engine.SessionStore.clear_expired() 

24 logger.info('Cleared all user sessions to deal with GHSA-2crp-q9pc-457j') 

25 except Exception: 

26 # Database may not be ready yet, so this does not matter anyhow 

27 pass 

28 

29class Migration(migrations.Migration): 

30 

31 atomic = False 

32 

33 dependencies = [ 

34 ("users", "0010_alter_apitoken_key"), 

35 ] 

36 

37 operations = [ 

38 migrations.RunPython( 

39 clear_sessions, reverse_code=migrations.RunPython.noop, 

40 ) 

41 ]