Skip to content
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

Fix chalice deployment bug introduced in #270 #316

Conversation

jlujan-invitae
Copy link
Contributor

Fix chalice deployment bug introduced in #270, closes #315

  • Refactor LocalLambdaClient into seperate file
  • try/catch import when running from a deployed lambda

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements (place an x in each [ ])

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

* Refactor LocalLambdaClient into seperate file
* try/catch import when running from a deployed lambda
@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #316 (6a596db) into main (c649e2b) will decrease coverage by 0.02%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #316      +/-   ##
==========================================
- Coverage   91.49%   91.46%   -0.03%     
==========================================
  Files         166      167       +1     
  Lines        5291     5298       +7     
==========================================
+ Hits         4841     4846       +5     
- Misses        450      452       +2     
Impacted Files Coverage Δ
slack_bolt/adapter/aws_lambda/chalice_handler.py 84.28% <70.00%> (-5.33%) ⬇️
...adapter/aws_lambda/chalice_lazy_listener_runner.py 100.00% <100.00%> (+5.26%) ⬆️
...ack_bolt/adapter/aws_lambda/local_lambda_client.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c649e2b...6a596db. Read the comment docs.

@seratch seratch added area:adapter bug Something isn't working labels Apr 28, 2021
@seratch seratch added this to the 1.6.0 milestone Apr 28, 2021
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the changes! Can you check my comments?

@@ -18,6 +18,7 @@
ChaliceSlackRequestHandler,
not_found,
)
from slack_bolt.adapter.aws_lambda.local_lambda_client import LocalLambdaClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalLambdaClient is not directly used in this test file. If you have some intention to have this here, can you add comments telling the reason why we should have this import.



class ChaliceSlackRequestHandler:
def __init__(self, app: App, chalice: Chalice): # type: ignore
def __init__(self, app: App, chalice: Chalice, lambda_client: Optional[Any] = None): # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a bit more specific type than Optional[Any] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual type is runtime generated by botocore from an API spec. It has a base of botocore.client.BaseClient. I will use that. However, it provides no real type information. Will also add a docstring with more details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I was also thinking we can use BaseClient at least.

try:
from slack_bolt.adapter.aws_lambda.local_lambda_client import LocalLambdaClient
except ImportError:
LocalLambdaClient = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about having a global variable like local_lambda_available value and moving the initial import of LocalLambdaClient to ChaliceSlackRequestHandler constructor? As Chalice apps have overhead for loading, I would like to avoid extra loading as much as possible.

* Only import LocalLambdaClient if CLI and client not passed in
* Add unittest for default lazy listener
@jlujan-invitae
Copy link
Contributor Author

I identified how this bug went undetected and wrote a description in an issue with the aws/chalice project. The gist is that I was using a specific git revision from my fork in our requirements.txt. Apparently, the chalice packer ignores source distribution and attempts to download a binary distribution by package name and version. Since my fork was pre-release, it detected the previous slack-bolt version and downloaded the available wheel from PyPI. Relevant issue is here aws/chalice#1700 (comment)

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating this. Apart from my comment about the test code, everything looks great to me. Can you check my comment?

with mock.patch.dict(os.environ, {"AWS_CHALICE_CLI_MODE": "false"}):
assert os.environ.get("AWS_CHALICE_CLI_MODE") == "false"

mock_s3 = mock.MagicMock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make sure if this is for s3 client. Is it a lambda client? (I might be missing something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. It is the lambda client. Will fix.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@seratch seratch merged commit e1b7a6f into slackapi:main Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:adapter bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug introduced in #270 causes Chalice deployments to produce failing lambda function
2 participants