Skip to content

GET /v1/objects/*: handle "attrs":[] as expected#8169

Merged
julianbrost merged 1 commit intomasterfrom
bugfix/object-query-all-attrs-8167
Jan 24, 2025
Merged

GET /v1/objects/*: handle "attrs":[] as expected#8169
julianbrost merged 1 commit intomasterfrom
bugfix/object-query-all-attrs-8167

Conversation

@Al2Klimov
Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov commented Aug 12, 2020

... i.e. yield no attrs and not all.

fixes #8167

@Al2Klimov Al2Klimov self-assigned this Aug 12, 2020
@Al2Klimov
Copy link
Copy Markdown
Member Author

Before

➜  icinga2 git:(master) prefix/sbin/icinga2 daemon -d
[2020-08-12 11:27:45 +0200] information/cli: Icinga application loader (version: v2.12.0)
[2020-08-12 11:27:45 +0200] information/cli: Closing console log.
➜  icinga2 git:(master) curl -k -s -u root:aa726742e5f78f78 -H 'Accept: application/json' 'https://localhost:5665/v1/objects/hosts?pretty=1' -X GET -d '{"attrs":[]}'
{
    "results": [
        {
            "attrs": {
                "__name": "alexanders-mbp.int.netways.de",
                "acknowledgement": 0.0,
...

After

➜  icinga2 git:(bugfix/object-query-all-attrs-8167) prefix/sbin/icinga2 daemon -d
[2020-08-12 11:38:12 +0200] information/cli: Icinga application loader (version: v2.12.0-1-gdbc1de9a1)
[2020-08-12 11:38:12 +0200] information/cli: Closing console log.
➜  icinga2 git:(bugfix/object-query-all-attrs-8167) curl -k -s -u root:8ed34c58bb15f62e -H 'Accept: application/json' 'https://localhost:5665/v1/objects/hosts?pretty=1' -X GET -d '{"attrs":[]}'
{
    "results": [
        {
            "attrs": {},
            "joins": {},
            "meta": {},
            "name": "alexanders-mbp.int.netways.de",
            "type": "Host"
        }
    ]
}
➜  icinga2 git:(bugfix/object-query-all-attrs-8167) curl -k -s -u root:8ed34c58bb15f62e -H 'Accept: application/json' 'https://localhost:5665/v1/objects/hosts?pretty=1'
{
    "results": [
        {
            "attrs": {
                "__name": "alexanders-mbp.int.netways.de",
                "acknowledgement": 0.0,
...

@Al2Klimov Al2Klimov removed their assignment Aug 12, 2020
@Al2Klimov Al2Klimov marked this pull request as ready for review August 12, 2020 09:41
@Al2Klimov Al2Klimov added area/api REST API bug Something isn't working labels Aug 12, 2020
@Al2Klimov Al2Klimov added this to the 2.13.0 milestone Aug 12, 2020
@Al2Klimov Al2Klimov force-pushed the bugfix/object-query-all-attrs-8167 branch from dbc1de9 to 242b3f7 Compare December 14, 2020 15:14
Copy link
Copy Markdown
Member

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

PR works as advertised, but is this a real issue? This might break compatibility in edge-cases, so I'd avoid doing so unless needed. Docs don't look like they state anything about what happens with an empty list. @N-o-X Any second opinions?

@Al2Klimov Al2Klimov requested a review from N-o-X January 11, 2021 10:54
@Al2Klimov
Copy link
Copy Markdown
Member Author

Which edge-cases e.g.?

@julianbrost
Copy link
Copy Markdown
Member

Just in general if you have some code that sometimes filters fields and until now used an empty list to get all fields until now. You easily get something like this when using Go's JSON marshaling, so that's why I was thinking of this. So if we do this, this shouldn't be backported to old releases.

@Al2Klimov
Copy link
Copy Markdown
Member Author

  1. Then you should use null/not at all and (if needed, I'm not quite sure about []string(nil)) work around this by using a *[]string, not just []string.
  2. I'm fine with not backporting something – whatever it is.

@Al2Klimov Al2Klimov modified the milestones: 2.13.0, 2.14.0 Jun 2, 2021
@Al2Klimov
Copy link
Copy Markdown
Member Author

@cla-bot check

@cla-bot cla-bot bot added the cla/signed label Aug 4, 2021
@julianbrost julianbrost removed the request for review from N-o-X January 17, 2023 15:03
@julianbrost julianbrost removed this from the 2.14.0 milestone Jan 24, 2023
@Al2Klimov Al2Klimov requested a review from yhabteab November 8, 2024 15:32
@Al2Klimov Al2Klimov added this to the 2.15.0 milestone Jan 21, 2025
... i.e. yield no attrs and not all.

refs #8167
@Al2Klimov Al2Klimov force-pushed the bugfix/object-query-all-attrs-8167 branch from 242b3f7 to e18c923 Compare January 21, 2025 10:37
@Al2Klimov Al2Klimov requested a review from oxzi January 22, 2025 11:38
Copy link
Copy Markdown
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

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

Generally speaking, this change is kinda trivial and should resolve the linked issue.

Even if I can only think about constructed scenarios where one explicitly wants an empty attrslist, the documentation describes this parameter as "[l]imited attribute list in the output".

Anyway, I think @julianbrost made a valid point in the prior comment, #8169 (comment). One can think of an API-facing script like the following, which would break.

def get_attrs():
    ''' Required attrs based on something™, but can be empty. '''
    return []
    # return ['name', 'address']


attrs = []
attrs.extend(get_attrs())

But it is questionable how many scripts may be out there dynamically creating an attrs list.

Thus, I would be in favor for this PR but only if it appears in the next non-patch release (currently 2.15) without backports and a descriptive entry in the changelog.

@julianbrost julianbrost merged commit 7888366 into master Jan 24, 2025
@julianbrost julianbrost deleted the bugfix/object-query-all-attrs-8167 branch January 24, 2025 08:14
@yhabteab yhabteab removed their request for review January 24, 2025 08:17
@julianbrost
Copy link
Copy Markdown
Member

Guess what relied on that behavior: Icinga/icingadb-web#1192 😄

@Al2Klimov
Copy link
Copy Markdown
Member Author

Don't worry, they handle this!

@yhabteab
Copy link
Copy Markdown
Member

Don't worry, they handle this!

But was this change worth it to break Icinga DB Web?

@Al2Klimov
Copy link
Copy Markdown
Member Author

Yes.

What did they even expect from explicitly passing an empty array??

@lippserd
Copy link
Copy Markdown
Member

What did they even expect from explicitly passing an empty array??

The phrasing of the question and the use of multiple punctuation marks convey an attitude that is inappropriate. The behavior in question is not clearly documented anywhere, and Icinga previously worked this way. The recent change is now being used as justification to pick on the Web code across several discussions. Stop making such a fuss. And to be frank, if the documentation states that the parameter limits the attributes, then specifying an empty array does not limit the attributes. Regardless of how the fix is handled in Web, the documentation should clearly state what is to be expected.

But was this change worth it to break Icinga DB Web?

Yes.

Of course not, all this is constructed work with zero benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api REST API bug Something isn't working cla/signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: object query w/ "attrs":[] yields all attrs, not none

5 participants