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
Plugin types: Tie a ResourceState to its corresponding ResourceDefinition #1346
Conversation
…ed when fetching defns for machine-only actions
… _wait_for Optional
c32739d
to
ece26ef
Compare
Otherwise, all the references have an Any
I'm not sure about this last commit, but I think we do need to specify it is as generic as possible. |
We'll get bogus hits, only check the concrete type.
Explicitly subclassed Protocols don't support super().__init__ ... but we need that. See: python/typing#572 for a description, including the below workaround. Protocol doesn't give us any special run-time behavior (except for runtime_checkable,) and can be pretty transparently swapped out for Generic at run time. By using Generic at run-time, we get the expected __init__ behavior. But, we still want Protocols at type-checking time because Protocol is much stricter about assigning to `self` without explicitly defining and typing the object variable. In conclusion, I'm sorry. Hopefully python/typing#572 gets fixed and we can delete this and go back to the isinstance check in deployment.py. Co-authored-by: Graham Christensen <graham.christensen@tweag.io>
@@ -1488,7 +1489,8 @@ def worker(m: nixops.resources.ResourceState) -> None: | |||
m._errored = True | |||
raise | |||
finally: | |||
m._destroyed_event.set() | |||
if dep._destroyed_event is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @grahamc this triggers the following error
if dep._destroyed_event is not None:
UnboundLocalError: local variable 'dep' referenced before assignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you catch this error? and why didn't I? :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Randomly xD
Was playing around a deployment containing some missing resource
+-----------------------+---------+-------------------+---------------------------------------+------------+
| Name | Status | Type | Resource Id | IP address |
+-----------------------+---------+-------------------+---------------------------------------+------------+
| test | Up | command-output | test-afc21edad3e1050cde1bde655014dd59 | |
| firstGrafanaDashboard | Missing | grafana-dashboard | | |
+-----------------------+---------+-------------------+---------------------------------------+------------+
And when I tried to destroy all resources, came across that error 🤞
$ nixops destroy -d grafana-test
warning: are you sure you want to destroy test? (y/N) y
test> destroying...
Traceback (most recent call last):
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/bin/nixops", line 11, in <module>
load_entry_point('nixops', 'console_scripts', 'nixops')()
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/__main__.py", line 705, in main
args.op(args)
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/script_defs.py", line 632, in op_destroy
include=args.include or [], exclude=args.exclude or [], wipe=args.wipe
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/deployment.py", line 1506, in destroy_resources
"destroy", lambda: self._destroy_resources(include, exclude, wipe)
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/deployment.py", line 1366, in run_with_notify
f()
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/deployment.py", line 1506, in <lambda>
"destroy", lambda: self._destroy_resources(include, exclude, wipe)
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/deployment.py", line 1496, in _destroy_resources
nr_workers=-1, tasks=list(self.resources.values()), worker_fun=worker
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/parallel.py", line 106, in run_tasks
raise list(exceptions.values())[0]
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/parallel.py", line 70, in thread_fun
work_result = (worker_fun(t), None, t.name)
File "/home/tewfikghariani/.cache/pypoetry/virtualenvs/nixops-grafana-FCCl2_6c-py3.7/src/nixops/nixops/deployment.py", line 1492, in worker
if dep._destroyed_event is not None:
UnboundLocalError: local variable 'dep' referenced before assignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @tewfic-ghariani! Oops! I've opened up a fixup PR. Can you give it a test? #1348
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine now! Thanks
dep._destroyed_event.wait() | ||
if dep._created_event is not None: | ||
dep._created_event.wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was buggy, too.
deployment.py: fixup mistakes in #1346
Using a protocol here makes mypy much more picky about variable definitions in the base classes (I think this is a good thing.) This helped find some hidden assumptions which are more correctly typed now.