mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix #384: duplicate tags due to case insensitivity
This commit is contained in:
		| @@ -442,8 +442,10 @@ class FileInfo: | |||||||
|     def _get_tags(cls, tags): |     def _get_tags(cls, tags): | ||||||
|         r = [] |         r = [] | ||||||
|         for t in tags.split(","): |         for t in tags.split(","): | ||||||
|             r.append( |             r.append(Tag.objects.get_or_create( | ||||||
|                 Tag.objects.get_or_create(slug=t, defaults={"name": t})[0]) |                 slug=t.lower(), | ||||||
|  |                 defaults={"name": t} | ||||||
|  |             )[0]) | ||||||
|         return tuple(r) |         return tuple(r) | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ from unittest import mock | |||||||
| from tempfile import TemporaryDirectory | from tempfile import TemporaryDirectory | ||||||
|  |  | ||||||
| from ..consumer import Consumer | from ..consumer import Consumer | ||||||
| from ..models import FileInfo | from ..models import FileInfo, Tag | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestConsumer(TestCase): | class TestConsumer(TestCase): | ||||||
| @@ -190,6 +190,20 @@ class TestAttributes(TestCase): | |||||||
|             () |             () | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     def test_case_insensitive_tag_creation(self): | ||||||
|  |         """ | ||||||
|  |         Tags should be detected and created as lower case. | ||||||
|  |         :return: | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         path = "Title - Correspondent - tAg1,TAG2.pdf" | ||||||
|  |         self.assertEqual(len(FileInfo.from_path(path).tags), 2) | ||||||
|  |  | ||||||
|  |         path = "Title - Correspondent - tag1,tag2.pdf" | ||||||
|  |         self.assertEqual(len(FileInfo.from_path(path).tags), 2) | ||||||
|  |  | ||||||
|  |         self.assertEqual(Tag.objects.all().count(), 2) | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestFieldPermutations(TestCase): | class TestFieldPermutations(TestCase): | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn