Recursive groups lookup #788
Replies: 3 comments 2 replies
-
Yes, I think it's fine to add. However, implementation-wise I'd suggest a similar implementation to has_parent_group. I think something like this may work:
You can basically handle the recursivity by calling yourself (Group is a subclass of Host), no need for another method. I haven't tested it though so I may be wrong. Also, this made me realize I am unsure if circular dependencies might be a problem here or somewhere else (two groups having each other as a parent) |
Beta Was this translation helpful? Give feedback.
-
yeah... I also forgot about it....
I am concerned that it might be expensive cpu-wise for an edge-case, specially when creating large inventories. Given nobody has complained about this ever I am tempted to just let it be and hope the user will search for the error in this repo and find this discussion... (because, that's what users typically do, right? right? :P) |
Beta Was this translation helpful? Give feedback.
-
Valid point. What if within that method, we just wrap it in a `try` and
raise a more descriptive error message that suggests there _might_ be
circular dependencies?
…On Thu, Mar 17, 2022, 01:20 David Barroso ***@***.***> wrote:
I must have skipped right over the extended_groups method
yeah... I also forgot about it....
It might make sense to build in a validation check within the Host class
so when the object is initialized or a group is added, a check runs to
ensure that it is not adding a circular dependency. I'd have to think a bit
on how to implement that though.
I am concerned that it might be expensive cpu-wise for an edge-case,
specially when creating large inventories. Given nobody has complained
about this ever I am tempted to just let it be and hope the user will
search for the error in this repo and find this discussion... (because,
that's what users typically do, right? right? :P)
—
Reply to this email directly, view it on GitHub
<#788 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI4H3ZUHP677SVXPT4P6IPTVALTLBANCNFSM5QZLYHUA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hello!
I have a case which I need to be able to see all parent groups, recursively, for a host. I know there is already the
has_parent_group
method, which is useful if you need to look for one specific group, but this does not satisfy my requirement.I played around with the code a bit and here is what I came up with as a prototype for doing this:
Is this something that might be useful to others? If so, I'd clean it up and create a PR.
Thanks,
Brandon
Beta Was this translation helpful? Give feedback.
All reactions