From e8aa870f90a975674743d7d9b3f591085e501040 Mon Sep 17 00:00:00 2001 From: Irfaan Mansoori Date: Mon, 18 May 2026 19:25:57 +0530 Subject: [PATCH] fix: memory leak in git.py by using cached_property Co-authored-by: Greyson LaLonde --- lib/cli/src/crewai_cli/git.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/cli/src/crewai_cli/git.py b/lib/cli/src/crewai_cli/git.py index fb08c391a..0b7600a76 100644 --- a/lib/cli/src/crewai_cli/git.py +++ b/lib/cli/src/crewai_cli/git.py @@ -1,4 +1,4 @@ -from functools import lru_cache +from functools import cached_property import subprocess @@ -9,7 +9,7 @@ class Repository: if not self.is_git_installed(): raise ValueError("Git is not installed or not found in your PATH.") - if not self.is_git_repo(): + if not self.is_git_repo: raise ValueError(f"{self.path} is not a Git repository.") self.fetch() @@ -40,13 +40,9 @@ class Repository: encoding="utf-8", ).strip() - @lru_cache(maxsize=None) # noqa: B019 + @cached_property # noqa: B019 def is_git_repo(self) -> bool: - """Check if the current directory is a git repository. - - Notes: - - TODO: This method is cached to avoid redundant checks, but using lru_cache on methods can lead to memory leaks - """ + """Check if the current directory is a git repository.""" try: subprocess.check_output( ["git", "rev-parse", "--is-inside-work-tree"], # noqa: S607