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

Saving commits in a list for later access won't give access to stats #283

Open
hcwang opened this issue Sep 15, 2023 · 3 comments
Open

Saving commits in a list for later access won't give access to stats #283

hcwang opened this issue Sep 15, 2023 · 3 comments
Labels
bug Something isn't working PR welcome Issue is confirmed, but not fixed yet

Comments

@hcwang
Copy link

hcwang commented Sep 15, 2023

Describe the bug

After upgrade from 2.5 to 2.5.1, the below code will raise exception.

To Reproduce

The below code:

commits = list(Repository(".",only_no_merge=True).traverse_commits())
commits[0].files
commits[0].lines

will raise:

AttributeError: 'NoneType' object has no attribute 'repo'

OS Version:

no-arch

@ishepard
Copy link
Owner

Thanks for raising the issue!
I just checked and this code works:

from pydriller import Repository

for commit in Repository("test-repos/small_repo", only_no_merge=True).traverse_commits():
    print(commit.lines)
    print(commit.files)

but this code doesn't work:

commits = list(Repository("test-repos/small_repo",only_no_merge=True).traverse_commits())
commits[0].files
commits[0].lines

Not sure why, we'll have to check. I will put this issue as a bug and PR are welcome

@ishepard ishepard added bug Something isn't working PR welcome Issue is confirmed, but not fixed yet labels Sep 15, 2023
@ishepard
Copy link
Owner

The reason is that the object is inside a context manager, so it will get destroyed after the loop.

I don't see a good solution to this, other than just iterating over the commits rather than putting them in a list.

@ishepard ishepard changed the title access commit.files or commit.lines will get an error: AttributeError: 'NoneType' object has no attribute 'repo' Saving commits in a list for later access won't give access to stats Sep 15, 2023
@hcwang
Copy link
Author

hcwang commented Dec 13, 2024

Any plan to fix this issue? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome Issue is confirmed, but not fixed yet
Projects
None yet
Development

No branches or pull requests

2 participants