From 4a15ec3ddc3d5a5830947c5ddb174a2503bc9e7c Mon Sep 17 00:00:00 2001 From: Lucas Ficheux Date: Tue, 8 Oct 2019 17:01:24 +0200 Subject: [PATCH] [cragr] Fix DateGuesser for some savings Somme savings Accounts have Transactions with a date without a year, we use a DateGuesser to guess that year. The DateGuesser wasn't properly handed to the method, that is what this patch fixes. For DateGuesser to fulfill it's purpose the same instance needs to be shared between all Transaction objects, or the default behaviour of *Element is to make a copy of the parent's env variable (the dictionnary used by the filter Env) so each Transaction would have a new instance of DateGuesser. Here we create a child class of DateGuesser with it's __deepcopy__ method overridden so that a call of deepcopy on it will return the object itself instead of a copy, this counteracts the behaviour of *Element and allows all Transaction objects to share the same instance of DateGuesser. This may break again. --- modules/cragr/regions/browser.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/cragr/regions/browser.py b/modules/cragr/regions/browser.py index 4e2cc13b51..f9e6eb629f 100644 --- a/modules/cragr/regions/browser.py +++ b/modules/cragr/regions/browser.py @@ -619,7 +619,13 @@ def iter_history(self, account, coming=False): ): self.unhandled_method(account.id) - date_guesser = LinearDateGuesser(date_max_bump=timedelta(30)) + class NoCopyLinearDateGuesser(LinearDateGuesser): + # params passed to a @method are deepcopied, in each iteration of ItemElement + # so we want to avoid repeatedly copying objects since we wan't to keep using the same object + def __deepcopy__(self, memo): + return self + + date_guesser = NoCopyLinearDateGuesser(date_max_bump=timedelta(30)) for tr in self.page.iter_history(date_guesser=date_guesser): yield tr -- GitLab