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

[bug] Duplicated functions decorated with @service are not exposed as such #121

Closed
wsw70 opened this issue Dec 16, 2020 · 3 comments
Closed

Comments

@wsw70
Copy link
Contributor

wsw70 commented Dec 16, 2020

I was debugging a time-based automation today that was not working and decided to expose it as a service. There was no way for me to make it seen in the HA dev tools.

I then realized that my code was similar to:

@service
def hello(**data):
    log.info("hello 1")

@service
def hello(**data):
    log.info("hello 2")

Specifically: I mistakenly called two functions the same.

There was no message in the HA logs about this. While it is conceivable that two functions are called the same (this is correct Python code and the second function wins) it is probably a mistake.

The fact that the service is not exposed is more "bug-like" and I guess that maybe some warning should be issued.

This is really low priority and I do not actually know whether this even qualifies as a bug, I just wanted to mention that in case it is by design and not documented.

@dlashua
Copy link
Contributor

dlashua commented Dec 16, 2020

There may be something @craigbarratt can do about this, but, in general, this is just how Python works.

def whatever() just means to store the following function in a place called "whatever". It's functionally similar to whatever = 15. If you, then later, issue whatever = 20 then it does, with no complaint. And if you later issue def whatever(): again, it does so without complaint as well. The function is just like any other variable. In fact, you can "def whatever():" and then later "whatever = 15" in the same scope (file, whatever)... and your whatever function is gone, with no complaint.

@wsw70
Copy link
Contributor Author

wsw70 commented Dec 16, 2020

Yes, I completely understand that part - this is why I mentioned that the two defs are correct Python code.

I just thought that in the context of automations this is probably a mistake, and especially the fact that @service does not expose the service in that case is disturbing (sorry not an English speaker - I do not want to sound dramatic :)).

I will close the issue, that could be useful if someone finds it when searching fr a similar problem.

@wsw70 wsw70 closed this as completed Dec 16, 2020
@craigbarratt
Copy link
Member

craigbarratt commented Dec 17, 2020

While redefining a function is normal (as discussed), it is a bug that the 2nd definition isn't exposed as a service. So re-opening until that bug is fixed.

@craigbarratt craigbarratt reopened this Dec 17, 2020
@wsw70 wsw70 changed the title [maybe a bug] Duplicated functions are not warned against and associated services are not exposed [bug] Duplicated functions decorated with @service are not exposed as such Dec 17, 2020
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

No branches or pull requests

3 participants