mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Fix bug in loading setting from cache (#5612)
* Fix bug in loading setting from cache - Need to bring out "cache" key first, otherwise it gets included in the calculated cache key - Reference: https://github.com/inventree/InvenTree/issues/5586 * Unit test fixes
This commit is contained in:
		| @@ -146,6 +146,7 @@ class BuildTest(BuildTestBase): | |||||||
|     def test_ref_int(self): |     def test_ref_int(self): | ||||||
|         """Test the "integer reference" field used for natural sorting""" |         """Test the "integer reference" field used for natural sorting""" | ||||||
|  |  | ||||||
|  |         # Set build reference to new value | ||||||
|         common.models.InvenTreeSetting.set_setting('BUILDORDER_REFERENCE_PATTERN', 'BO-{ref}-???', change_user=None) |         common.models.InvenTreeSetting.set_setting('BUILDORDER_REFERENCE_PATTERN', 'BO-{ref}-???', change_user=None) | ||||||
|  |  | ||||||
|         refs = { |         refs = { | ||||||
| @@ -168,6 +169,9 @@ class BuildTest(BuildTestBase): | |||||||
|             build.save() |             build.save() | ||||||
|             self.assertEqual(build.reference_int, ref_int) |             self.assertEqual(build.reference_int, ref_int) | ||||||
|  |  | ||||||
|  |         # Set build reference back to default value | ||||||
|  |         common.models.InvenTreeSetting.set_setting('BUILDORDER_REFERENCE_PATTERN', 'BO-{ref:04d}', change_user=None) | ||||||
|  |  | ||||||
|     def test_ref_validation(self): |     def test_ref_validation(self): | ||||||
|         """Test that the reference field validation works as expected""" |         """Test that the reference field validation works as expected""" | ||||||
|  |  | ||||||
| @@ -214,6 +218,9 @@ class BuildTest(BuildTestBase): | |||||||
|                 title='Valid reference', |                 title='Valid reference', | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|  |         # Set build reference back to default value | ||||||
|  |         common.models.InvenTreeSetting.set_setting('BUILDORDER_REFERENCE_PATTERN', 'BO-{ref:04d}', change_user=None) | ||||||
|  |  | ||||||
|     def test_next_ref(self): |     def test_next_ref(self): | ||||||
|         """Test that the next reference is automatically generated""" |         """Test that the next reference is automatically generated""" | ||||||
|  |  | ||||||
| @@ -238,6 +245,9 @@ class BuildTest(BuildTestBase): | |||||||
|         self.assertEqual(build.reference, 'XYZ-000988') |         self.assertEqual(build.reference, 'XYZ-000988') | ||||||
|         self.assertEqual(build.reference_int, 988) |         self.assertEqual(build.reference_int, 988) | ||||||
|  |  | ||||||
|  |         # Set build reference back to default value | ||||||
|  |         common.models.InvenTreeSetting.set_setting('BUILDORDER_REFERENCE_PATTERN', 'BO-{ref:04d}', change_user=None) | ||||||
|  |  | ||||||
|     def test_init(self): |     def test_init(self): | ||||||
|         """Perform some basic tests before we start the ball rolling""" |         """Perform some basic tests before we start the ball rolling""" | ||||||
|  |  | ||||||
|   | |||||||
| @@ -450,6 +450,9 @@ class BaseInvenTreeSetting(models.Model): | |||||||
|             **cls.get_filters(**kwargs), |             **cls.get_filters(**kwargs), | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         # Unless otherwise specified, attempt to create the setting | ||||||
|  |         create = kwargs.pop('create', True) | ||||||
|  |  | ||||||
|         # Perform cache lookup by default |         # Perform cache lookup by default | ||||||
|         do_cache = kwargs.pop('cache', True) |         do_cache = kwargs.pop('cache', True) | ||||||
|  |  | ||||||
| @@ -478,9 +481,6 @@ class BaseInvenTreeSetting(models.Model): | |||||||
|         # Setting does not exist! (Try to create it) |         # Setting does not exist! (Try to create it) | ||||||
|         if not setting: |         if not setting: | ||||||
|  |  | ||||||
|             # Unless otherwise specified, attempt to create the setting |  | ||||||
|             create = kwargs.pop('create', True) |  | ||||||
|  |  | ||||||
|             # Prevent creation of new settings objects when importing data |             # Prevent creation of new settings objects when importing data | ||||||
|             if InvenTree.ready.isImportingData() or not InvenTree.ready.canAppAccessDatabase(allow_test=True, allow_shell=True): |             if InvenTree.ready.isImportingData() or not InvenTree.ready.canAppAccessDatabase(allow_test=True, allow_shell=True): | ||||||
|                 create = False |                 create = False | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ def currency_code_default(): | |||||||
|     from common.models import InvenTreeSetting |     from common.models import InvenTreeSetting | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY', create=False, cache=False) |         code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY', create=True, cache=True) | ||||||
|     except Exception:  # pragma: no cover |     except Exception:  # pragma: no cover | ||||||
|         # Database may not yet be ready, no need to throw an error here |         # Database may not yet be ready, no need to throw an error here | ||||||
|         code = '' |         code = '' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user