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 exception on accessing missing attribute on JobStatus #619

Merged
merged 1 commit into from
Apr 26, 2020

Conversation

pmrv
Copy link
Contributor

@pmrv pmrv commented Apr 26, 2020

When (accidentally) trying to access a job status check that is not actually defined, like job.status.queued instead of job.status.submitted you'd get a weird error message like this

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-50-ac32335f0f7e> in <module>
----> 1 jre.status.foo

~/software/pyiron/pyiron/base/job/jobstatus.py in __getattr__(self, name)
    243             return self._status_dict[name]
    244         else:
--> 245             super(JobStatus, self).__getattr__(name)
    246 
    247     def __setattr__(self, name, value):

AttributeError: 'super' object has no attribute '__getattr__'

which doesn't explain the actual issue (that you typed the wrong name).

The previous implementation of __getattr__ tried to escalate to
object.__getattr__ if the requested attribute name is not one of the
status names, probably to keep normal attribute lookup working. But
this is not needed because python first calls __getattribute__ to do the
normal lookup and only then calls __getattr__ if it is defined1 and
since object doesn't define __getattr__ this gave a weird exception when
you tried to access JobStatus.status_name and got the status name wrong.

This now raises the proper AttributeError, while keeping normal
attribute access intact.

Not a big problem, but I stumbled on this this morning, because I mixed up the status names.

the previous implementation of __getattr__ tried to escalate to
object.__getattr__ if the requested attribute name is not one of the
status names, probably to keep normal attribute lookup working.  But
this is not needed because python first calls __getattribute__ to do the
normal lookup and only then calls __getattr__ if it is defined[1] and
since object doesn't define __getattr__ this gave a weird exception when
you tried to access JobStatus.status_name and got the status name wrong.

This now raises the proper AttributeError, while keeping normal
attribute access intact.

[1]: https://docs.python.org/3/reference/datamodel.html?highlight=__getattribute__#object.__getattribute__
@pmrv pmrv requested a review from jan-janssen April 26, 2020 09:19
@pmrv pmrv changed the title fix exception on accessing missing attribute fix exception on accessing missing attribute on JobStatus Apr 26, 2020
@coveralls
Copy link

Pull Request Test Coverage Report for Build 4316

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 56.996%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron/base/job/jobstatus.py 0 1 0.0%
Totals Coverage Status
Change from base Build 4314: 0.0%
Covered Lines: 11777
Relevant Lines: 20663

💛 - Coveralls

Copy link
Member

@jan-janssen jan-janssen left a comment

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 guess the super part came from a time when job status was derived from string.

@pmrv pmrv merged commit 546f607 into master Apr 26, 2020
@jan-janssen jan-janssen deleted the jobstatus_attr branch April 26, 2020 12:18
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.

3 participants