tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

`before_sleep_log` logs "<unknown>"

Open geuben opened this issue 1 year ago • 5 comments

When running code similar to the "Retrying code block" example and using the before_sleep_log function, the logged line includes ""

Seems like this comment is untrue: https://github.com/jd/tenacity/blob/99e7482e8b027f0521315e0f7830a0badae5c561/tenacity/before_sleep.py#L60

Screenshot 2024-01-08 at 21 16 05

geuben avatar Jan 08 '24 21:01 geuben

running 8.2.3

geuben avatar Jan 08 '24 21:01 geuben

I guess the comment dates from the time when only the function decorator was available.

jd avatar Jan 09 '24 08:01 jd

That was my assumption too.

I had a quick scan of the code and I couldn't see a nice way to be able to name the retry block so that this log would print something more useful.

geuben avatar Jan 09 '24 09:01 geuben

#455

christopher5106 avatar Apr 15 '24 11:04 christopher5106

@christopher5106 @geuben As a workaround, just use attempt.retry_state.fn = func_name (or self.func_name) inside with attempt: and it should work as expected. 👍

paulofreitas avatar Jun 05 '24 06:06 paulofreitas