Skip to content

Commit

Permalink
UserCache.get_pr_from_commit: check if commit exists first
Browse files Browse the repository at this point in the history
As the underlying dict is a nested dictionary which sets automatically a
value for each accessed key, accessing the commit_sha directly even if
it doesn't exist was updating the cache for nothing.
  • Loading branch information
sebalix committed Jan 9, 2025
1 parent 2779855 commit 8bb2043
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion oca_port/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def store_commit_pr(self, commit_sha: str, data):

def get_pr_from_commit(self, commit_sha: str):
"""Return the original PR data of a commit."""
pr_number = self._commits_to_port["commits"][commit_sha]["pr"]
pr_number = None
if commit_sha in self._commits_to_port["commits"]:
pr_number = self._commits_to_port["commits"][commit_sha]["pr"]
if pr_number:
return self._commits_to_port["pull_requests"][str(pr_number)]
return {}
Expand Down

0 comments on commit 8bb2043

Please sign in to comment.