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 AttributeError 'Verificators' on model.verifiers call #128

Merged
merged 3 commits into from
Jan 15, 2023

Conversation

xispa
Copy link
Member

@xispa xispa commented Jan 14, 2023

Description of the issue/feature this PR addresses

This Pull Request fixes an AttributeError when calling the attribute verifiers from an AnalysisRequest's model within a results report template:

<tal:something define="collection view/collection;
                       verifiers python: map(lambda m: m.verifiers, collection);">
   ...
</tal:something>

Current behavior before PR

AttributeError: 'Verificators'

Desired behavior after PR is merged

No AttributeError. Verifier users are returned

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa requested a review from ramonski January 14, 2023 13:04
@xispa xispa added the Bug label Jan 14, 2023
userids = list(itertools.chain.from_iterable(userids))
# remove empties
userids = filter(None, userids)
# get the users
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think it would make more sense to have here some nested for loops instead of iterating multiple times through the list.

I think on something like this (untested):

users = []
for analysis in self.Analyses:
    for verificators in analysis.getVerificators():
        for userid in verificators:
            if not userid:
                continue
            user = api.get_user(userid)
            if not user:
                continue
            if user in users:
                continue
            users.append(user)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO three nested fors are uglier than this "flatten" approach. Note that you are iterating through the list of users inside the loop each time you get a user, while I simply remove duplicates of userids before looping.

I think that since we don't expect these lists of verifiers to be huge (in most cases, 1 per sample and most samples will share same verifier), the performance impact caused by iterating three times is negligible. I can remove the filter(None, userids) and perform the check inside the loop though.

@ramonski ramonski merged commit e0e4208 into 2.x Jan 15, 2023
@ramonski ramonski deleted the fix-attribute-error-verifiers branch January 15, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants