Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Check is not None in safe_get #158

Merged
merged 1 commit into from
Sep 20, 2019

Conversation

qlemaire22
Copy link
Contributor

@qlemaire22 qlemaire22 commented Sep 6, 2019

Hi,

I would add a check to see if self.value is not None in safe_get.

Otherwise it can create a TypeError: argument of type 'NoneType' is not iterable which I faced when working on Apache Airflow. I believe that I would be easier to debug.

@k8s-ci-robot
Copy link
Contributor

Welcome @qlemaire22!

It looks like this is your first PR to kubernetes-client/python-base 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python-base has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 6, 2019
@qlemaire22
Copy link
Contributor Author

I signed it!

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 6, 2019
@qlemaire22 qlemaire22 changed the title Fix safe get safety condition Check in not None in safe get Sep 6, 2019
@qlemaire22 qlemaire22 changed the title Check in not None in safe get Check is not None in safe_get Sep 6, 2019
@qlemaire22
Copy link
Contributor Author

/assign @roycaihw

@@ -494,7 +494,7 @@ def __len__(self):

def safe_get(self, key):
if (isinstance(self.value, list) and isinstance(key, int) or
key in self.value):
self.value is not None and key in self.value):
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test for this. Do you have a kubeconfig yaml that reproduces the error?

self.value should be either a list or a dict. I think we should restrict ConfigNade with None value early if we have such a case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. In my case, it happened when calling _get_kube_config_loader_for_yaml_file with no kubeconfig available. Should I raise an error somewhere like in KubeConfigMerger, KubeConfigLoader or ConfigNode to warn about empty kube_config?

Copy link
Member

Choose a reason for hiding this comment

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

could you add checks in both _get_kube_config_loader_for_yaml_file and KubeConfigLoader?

In _get_kube_config_loader_for_yaml_file an error should be raised if kcfg.config is None. This is likely be caused by invalid kubeconfig file path. This error restores the old behavior we had

In KubeConfigLoader an error should be raised if the input config_dict is None. This makes the error more obvious if someone (unlikely) uses the KubeConfigLoader directly with a None config_dict object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did add the two checks. Please, tell me if I should put more specific error messages.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 17, 2019
@codecov-io
Copy link

codecov-io commented Sep 17, 2019

Codecov Report

Merging #158 into master will decrease coverage by 0.12%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #158      +/-   ##
==========================================
- Coverage   93.56%   93.44%   -0.13%     
==========================================
  Files          13       13              
  Lines        1384     1388       +4     
==========================================
+ Hits         1295     1297       +2     
- Misses         89       91       +2
Impacted Files Coverage Δ
config/kube_config.py 87.76% <60%> (-0.4%) ⬇️

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 5092d96...a29bf29. Read the comment docs.

if isinstance(config_dict, ConfigNode):
if config_dict is None:
raise ConfigException(
'Invalid kube-config file. '
Copy link
Member

Choose a reason for hiding this comment

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

config_dict here doesn't necessarily come from a kubeconfig file. Change the error message to Invalid kube config. Expected config_dict to not be None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I changed the error message.

@roycaihw
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qlemaire22, roycaihw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 20, 2019
@k8s-ci-robot k8s-ci-robot merged commit af42f24 into kubernetes-client:master Sep 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants