You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`validate_files(file_paths)` - Validate that files can be loaded
136
+
-`clear_cache()` - Clear the file loader cache (see File Loader Caching section)
136
137
137
138
#### Configuration Management
138
139
The converter maintains state and can be reconfigured:
@@ -237,6 +238,35 @@ Run `python scripts/generate_docs.py` when:
237
238
- Adding or removing classes
238
239
- Updating docstrings for clarity
239
240
241
+
### File Loader Caching Issue
242
+
243
+
**IMPORTANT**: The file loader (`lkml2cube/parser/loader.py`) uses a global `visited_path` dictionary to track which files have been processed to prevent infinite recursion when resolving includes. This caching mechanism can cause issues in certain scenarios:
244
+
245
+
#### Common Problems:
246
+
1.**Test Failures**: When running multiple tests that load the same files, the cache may prevent files from being reloaded, causing tests to fail with `None` results
247
+
2.**Stale Data**: In long-running processes or repeated calls, cached file paths may contain stale data
248
+
3.**Development Issues**: When developing and testing, the cache might prevent seeing changes to included files
249
+
250
+
#### Solutions:
251
+
1.**Clear Cache Method**: The `LookMLConverter` class provides a `clear_cache()` method that resets the `visited_path` dictionary
252
+
2.**Test Setup**: In tests, always call `visited_path.clear()` or `converter.clear_cache()` before loading files
253
+
3.**Fresh State**: For reliable results, clear the cache between different file loading operations
254
+
255
+
#### Example Usage:
256
+
```python
257
+
# In tests
258
+
from lkml2cube.parser.loader import visited_path
259
+
visited_path.clear() # Clear cache before loading
260
+
261
+
# Or using the converter
262
+
converter = LookMLConverter()
263
+
converter.clear_cache() # Clear cache before operations
264
+
result = converter.cubes("path/to/file.lkml")
265
+
```
266
+
267
+
#### Why This Happens:
268
+
The `visited_path` is a module-level global variable that persists between function calls. This is necessary to prevent infinite recursion when files include each other, but can cause unexpected behavior when the same files are loaded multiple times in different contexts.
269
+
240
270
### Code Review Checklist
241
271
242
272
Before committing changes:
@@ -245,6 +275,7 @@ Before committing changes:
245
275
-[ ] Generated docs reflect the changes
246
276
-[ ] Examples in docstrings are accurate
247
277
-[ ] Parameter types and descriptions are correct
278
+
-[ ] Tests clear the file loader cache when needed
0 commit comments