-
Notifications
You must be signed in to change notification settings - Fork 421
Static typing: The add_handler API from logger was removed #2377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Apologies, closing, cannot reproduce it again. |
|
Hey @alexandreczg - did you get a runtime error or was a static checker error saying the method doesn't exist? The former would be a regression tho I can't reproduce it either. If it's the latter, we can address that with a PR to implement it and proxy it to _logger.addHandler so mypy is happy. This is the change I made that would cause the latter but not the former (tested with a stream handler + file log handler now). Please let us know ;) PS: No need to apologise, better safe than sorry and we appreciate your time flagging it very much!! |
Hey @heitorlessa, thank your for addressing this, commendable your dedication! It was a typing error actually, not runtime. I use pyright/pylance (vscode). I freaked out since it had been a long hours day and when I was about to push my code I start getting that error. Couldn't really understand it since it had been working. I regressed to version 2.4.0 (it was my last stable version) but quickly realized that I had implemented the new batch partial processor (SQS). So, I went back to 2.16.0 and magically the linting error went way... I'm not sure what or how it all happened, but when I introspected the logger class, I couldn't find the I'll keep your and this thread updated if something is to change now that I have pushed my code to AWS and using latest layer. 🤞 |
@heitorlessa , okay in version 2.16.1 the issue is back |
That's the piece I mentioned it's expected -- does it fail if you run it? Pyright (what Pylance uses) can't infer through the object proxy so it believes it doesn't exist. At runtime, it works. If you can confirm it works, feel free to make a PR adding a "addHandler" method that call self._logger.addHandler so Pylance will be happy in the next release - more than happy to accommodate that ;) |
Hi @heitorlessa, I can confirm it works. I will look into how I can open a PR to fix the linting. Another note, unrelated but would like your eyes on the batch_processor. I don't think it is working as it should: It is doing with processor(records, record_handler, context):
processor.process() with an empty list of records which of course returns:
I don't think this is supposed to happen. Please, correct me if I am wrong. I will create a new bug ticket if needed for tracking purposes. Edit: Better screenshot with filename included. |
This is now released under 2.16.2 version! |
hey @alexandreczg - we included the on Batch, please create an issue describing your intended outcome. The reason we're defensively catching As to An empty from aws_lambda_powertools.utilities.batch import (
AsyncBatchProcessor,
EventType,
async_process_partial_response,
)
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
from aws_lambda_powertools.utilities.typing import LambdaContext
processor = AsyncBatchProcessor(event_type=EventType.SQS)
async def async_record_handler(record: SQSRecord):
...
def lambda_handler(event, context: LambdaContext):
records = event.get("Records", [])
# This will fail because `records` is no longer a Dict
return async_process_partial_response(
event=records, record_handler=async_record_handler, processor=processor, context=context
) |
@heitorlessa thank your for the quick around on this 🙇 |
Expected Behaviour
In version 2.4.0 adding a handler to the log was easy. I would expect adding a handler to my log to be as simple as addHandler.
Current Behaviour
Method doesn't exist
Code snippet
But that API was removed on version 2.15.0. I depend on it to be able to log to cloudwatch and other places. I was reading the changelog but could not find any reference to this.
the only way around of this is to mess with the internals:
The text was updated successfully, but these errors were encountered: