Repository: tefra/xsdata
Pull request #990 (2024-03-22 18:55:03)

feat: Add xsdata version in the cli cache key
## 📒 Description

> Write a brief description of your PR.

Resolves #xxxx

## 🔗 What I've Done

> Write a description of the steps taken to resolve the issue

## 💬 Comments

> A place to write any comments to the reviewer.

## 🛫 Checklist

- [ ] Updated docs
- [ ] Added unit-tests
- [ ] [Sample tests](https://github.com/tefra/xsdata-samples) pass
- [ ] [W3C tests](https://github.com/tefra/xsdata-w3c-tests) pass


sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=990) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=tefra_xsdata&pullRequest=990&resolved=false&inNewCodePeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/component_measures?id=tefra_xsdata&pullRequest=990&metric=new_accepted_issues&view=list)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=tefra_xsdata&pullRequest=990&resolved=false&inNewCodePeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/no-data-16px.png '') No data about Coverage  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=tefra_xsdata&pullRequest=990&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=990)



Patch:
diff --git a/xsdata/codegen/transformer.py b/xsdata/codegen/transformer.py
index 9e2db8bb..d0fce0c3 100644
--- a/xsdata/codegen/transformer.py
+++ b/xsdata/codegen/transformer.py
@@ -10,6 +10,7 @@ from typing import Callable, Dict, List, NamedTuple, Optional, Tuple
 
 from toposort import CircularDependencyError
 
+from xsdata import __version__
 from xsdata.codegen import opener
 from xsdata.codegen.container import ClassContainer
 from xsdata.codegen.exceptions import CodegenError
@@ -445,4 +446,4 @@ class ResourceTransformer:
         """
         key = hashlib.md5("".join(uris).encode()).hexdigest()
         tempdir = tempfile.gettempdir()
-        return Path(tempdir).joinpath(f"{key}.cache")
+        return Path(tempdir).joinpath(f"xsdata.{__version__}.{key}.cache")


Test patch:
diff --git a/tests/codegen/test_transformer.py b/tests/codegen/test_transformer.py
index 0cc139c9..7d8426a9 100644
--- a/tests/codegen/test_transformer.py
+++ b/tests/codegen/test_transformer.py
@@ -5,6 +5,7 @@ from unittest import mock
 
 from toposort import CircularDependencyError
 
+from xsdata import __version__
 from xsdata.codegen.container import ClassContainer
 from xsdata.codegen.exceptions import CodegenError
 from xsdata.codegen.mappers import (
@@ -483,6 +484,8 @@ class ResourceTransformerTests(FactoryTestCase):
         uris = ["a.xml", "b.json"]
         actual = self.transformer.get_cache_file(uris)
         tempdir = Path(tempfile.gettempdir())
-        expected = tempdir.joinpath("ae1bed744d3d3611e698a2d2ef5335d2.cache")
+        expected = tempdir.joinpath(
+            f"xsdata.{__version__}.ae1bed744d3d3611e698a2d2ef5335d2.cache"
+        )
 
         self.assertEqual(expected, actual)