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: len(None) bug #643

Merged
merged 5 commits into from
Feb 20, 2025
Merged

fix: len(None) bug #643

merged 5 commits into from
Feb 20, 2025

Conversation

joseph-sentry
Copy link
Contributor

@joseph-sentry joseph-sentry commented Feb 19, 2025

when the versioning system is None, list_relevant_files returns None so this changes the code in the upload_collector and the network_finder to handle that case

Fixes: #641

@joseph-sentry joseph-sentry requested a review from a team February 19, 2025 20:44
Copy link

sentry-io bot commented Feb 19, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: codecov_cli/services/upload/upload_collector.py

Function Unhandled Issue
generate_upload_data TypeError: object of type 'NoneType' has no len() Upload Coverag...
Event Count: 348
generate_upload_data TypeError: can only concatenate list (not "tuple") to list codecov_cli.services.upload.file_finder in ...
Event Count: 12
generate_upload_data TypeError: 'NoneType' object is not iterable Uplo...
Event Count: 2
generate_upload_data TypeError: object of type 'NoneType' has no len() Do Uploa...
Event Count: 2

Did you find this useful? React with a 👍 or 👎

Copy link

codecov bot commented Feb 19, 2025

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
3570 5 3565 0
View the top 3 failed test(s) by shortest run time
api.temp.calculator.test_calculator::test_divide
Stack Traces | 0.001s run time
def
                test_divide():
                > assert Calculator.divide(1, 2) == 0.5
                E assert 1.0 == 0.5
                E + where 1.0 = <function Calculator.divide at 0x104c9eb90>(1, 2)
                E + where <function Calculator.divide at 0x104c9eb90> = Calculator.divide
                .../temp/calculator/test_calculator.py:30: AssertionError
api.temp.calculator.test_calculator::test_divide
Stack Traces | 0.001s run time
def
                test_divide():
                > assert Calculator.divide(1, 2) == 0.5
                E assert 1.0 == 0.5
                E + where 1.0 = <function Calculator.divide at 0x104c9eb90>(1, 2)
                E + where <function Calculator.divide at 0x104c9eb90> = Calculator.divide
                .../temp/calculator/test_calculator.py:30: AssertionError
api.temp.calculator.test_calculator::test_divide
Stack Traces | 0.001s run time
def
                test_divide():
                > assert Calculator.divide(1, 2) == 0.5
                E assert 1.0 == 0.5
                E + where 1.0 = <function Calculator.divide at 0x104c9eb90>(1, 2)
                E + where <function Calculator.divide at 0x104c9eb90> = Calculator.divide
                .../temp/calculator/test_calculator.py:30: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link

github-actions bot commented Feb 19, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

webknjaz added a commit to webknjaz/ansible--awx-plugins that referenced this pull request Feb 19, 2025
This is an upstream bug that is being fixed. This patch will have to
be reverted.

Refs:
* codecov/codecov-cli#641
* codecov/codecov-cli#643
nora-codecov
nora-codecov previously approved these changes Feb 19, 2025
@@ -20,7 +20,7 @@ def __init__(
def find_files(self, ignore_filters=False) -> typing.List[str]:

Choose a reason for hiding this comment

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

Is mypy run on this project?
If files is None (as described in the PR description), your changed code surely results in returning None, in which case this annotation is wrong and there's a good chance another part of the codebase could mess up when expecting a list.

Copy link

@Dreamsorcerer Dreamsorcerer Feb 20, 2025

Choose a reason for hiding this comment

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

OK, I see the root problem (which confirms to me that this is not being checked by mypy, as it should have errored here).

The method is defined on the base class, but it's not an abstract method. So, if inherited (or instantiated directly), this returns None, even though the annotation says it returns a list (which is a clear type error that would be caught by any type checker):

def list_relevant_files(self, directory: t.Optional[Path] = None) -> t.List[str]:
pass

I think the correct fix is to either replace that pass with a return [], so it actually does the correct behaviour, or to turn those methods into abstract methods and require the subclass to define them correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I've implemented the ABC / abstractmethod suggestion.

the bug was the the NoVersioningSystem class was not defining the
list_relevant_files method, which meant it as falling back to the
VersioningSystemInterface definition which returns None.

This commit make the VersioningSystemInterface an ABC and makes all
the relevant methods abstract, then implements the methods on the
VersioningSystem implementations.
@@ -166,7 +166,7 @@ def generate_upload_data(
f"Found {len(report_files)} {report_type.value} files to report"
)
logger.debug(
f"Found {len(network)} network files to report, ({len(unfiltered_network)} without filtering)"
f"Found {len(network) if network else None} network files to report, ({len(unfiltered_network) if network else None} without filtering)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f"Found {len(network) if network else None} network files to report, ({len(unfiltered_network) if network else None} without filtering)"
f"Found {len(network) if network else 0} network files to report, ({len(unfiltered_network) if network else 0} without filtering)"

@thomasrockhu-codecov thomasrockhu-codecov merged commit b1a69ee into main Feb 20, 2025
18 of 19 checks passed
@thomasrockhu-codecov thomasrockhu-codecov deleted the joseph/fix-none-bug branch February 20, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: object of type 'NoneType' has no len() when uploading coverage
4 participants