Skip to content

[glance]: handle various image struct member types - #3159

Open
kayrus wants to merge 1 commit into
gophercloud:mainfrom
kayrus:glance-formats
Open

kayrus wants to merge 1 commit into
gophercloud:mainfrom
kayrus:glance-formats

Conversation

@kayrus

@kayrus kayrus commented Jul 26, 2024

Copy link
Copy Markdown
Contributor

Fixes #3147

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

[PUT URLS HERE]

@github-actions github-actions Bot added edit:image This PR updates image code semver:patch No API change labels Jul 26, 2024
@coveralls

coveralls commented Jul 26, 2024 •

Copy link
Copy Markdown

Coverage Status

coverage: 78.709% (-0.02%) from 78.726%
when pulling 5411d4a on kayrus:glance-formats
into 8caccbb on gophercloud:master.

@kayrus
kayrus requested a review from pierreprinetti July 26, 2024 13:26
@pierreprinetti

Copy link
Copy Markdown
Member

I'd really love to have @stephenfin's eyes on this first

@kayrus
kayrus requested a review from stephenfin July 26, 2024 13:47
@kayrus

kayrus commented Sep 20, 2024

Copy link
Copy Markdown
Contributor Author

@stephenfin any updates?

@kayrus

kayrus commented Sep 24, 2024

Copy link
Copy Markdown
Contributor Author

This is required to fix the terraform-provider-openstack/terraform-provider-openstack#1703

@kayrus
kayrus requested a review from a team September 24, 2024 09:05

@stephenfin stephenfin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

God I hate the Glance API 😞

Two asks for comments inline but I'm otherwise good. Sorry for the delay: I missed the ask.

Comment thread openstack/image/v2/images/results.go Outdated
Comment on lines +128 to +166
switch t := s.Hidden.(type) {
case nil:
r.Hidden = false
case bool:
r.Hidden = t
case string:
r.Hidden, err = strconv.ParseBool(t)
if err != nil {
return fmt.Errorf("Failed to parse Hidden %q: %v", t, err)
}
default:
return fmt.Errorf("Unknown type for Hidden: %v (value: %v)", reflect.TypeOf(t), t)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How is this happening. This should always be a boolean since that's how it's stored in the DB (source) and the API is simply using exactly what is stored there (source).

Sorry, you explained this in the issue. It's been a while 😅 Would it be possible to get a comment here explaining what's going on for future us (without needing to search though GitHub Issues)

"updated_at": "2014-05-05T17:15:11Z",
"visibility": "public",
"os_hidden": false,
"os_hidden": "False",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could do with a note about what we're simulating here also...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@kayrus
kayrus force-pushed the glance-formats branch 3 times, most recently from 520b250 to e96c3c2 Compare October 10, 2024 19:12
@kayrus kayrus changed the title [glance]: handle various Hidden/Properties formats [glance]: handle various image struct member types Oct 10, 2024
@kayrus
kayrus force-pushed the glance-formats branch 2 times, most recently from 3815ffc to d4aeae5 Compare October 10, 2024 19:23
@kayrus kayrus added the backport-v2 This PR will be backported to v2 label Oct 11, 2024
Comment on lines +126 to +129
r.Name, err = assert.String(s.Name, "Name")
if err != nil {
return err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this necessary? What's the difference between this and regular json unmarshalling with omitempty?

Ditto all other uses of String below.

Comment thread internal/assert/assert.go
@@ -0,0 +1,70 @@
package assert

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These aren't assertions. These are format conversions. jsonhelpers maybe?

Comment thread internal/assert/assert.go

const errf = "unknown type for %s: %T (value: %v)"

func Int(v any, name string) (int, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NumberOrString?

Comment thread internal/assert/assert.go
return 0, fmt.Errorf(errf, name, v, v)
}

func Int64(v any, name string) (int64, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you made NumberOrString generic on the return type you wouldn't need this function at all.

type ConvertibleNumber interface { int | int64 | float32 | float64 }

Comment thread internal/assert/assert.go
return 0, fmt.Errorf(errf, name, v, v)
}

func String(v any, name string) (string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is necessary.

Comment thread internal/assert/assert.go
return "", fmt.Errorf(errf, name, v, v)
}

func Bool(v any, name string) (bool, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BoolOrString?

@bkranendonk

Copy link
Copy Markdown

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

@kayrus

kayrus commented Dec 13, 2024

Copy link
Copy Markdown
Contributor Author

I didn't expect that anyone else is interested in this PR.

@stephenfin

Copy link
Copy Markdown
Contributor

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

It looks like there's a few outstanding comments from @mdbooth that need addressing/response first?

@rmnijgh

rmnijgh commented Apr 8, 2025

Copy link
Copy Markdown

Any updates? @stephenfin @pierreprinetti @mdbooth

@stephenfin

Copy link
Copy Markdown
Contributor

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

It looks like there's a few outstanding comments from @mdbooth that need addressing/response first?

This is still true?

@WizardBit

Copy link
Copy Markdown

@kayrus are you still working on this PR? Looks like there's a few comments that need to be resolved

@kayrus

kayrus commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

@WizardBit not at the moment. feel free to submit a new PR.

@WizardBit

Copy link
Copy Markdown

@WizardBit not at the moment. feel free to submit a new PR.

Unfortunately I am unfamiliar with Go, but thank you for the update

@rmnijgh

rmnijgh commented Oct 16, 2025

Copy link
Copy Markdown

Is this pull request dead? I'm unfamiliar with Go aswell but this is still a affecting problem for our Terraform users.

@stephenfin

Copy link
Copy Markdown
Contributor

Is this pull request dead? I'm unfamiliar with Go aswell but this is still a affecting problem for our Terraform users.

As kayrus said, this needs someone else to pick up the work until when they've time to work on it again.

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

Labels

backport-v2 This PR will be backported to v2 edit:image This PR updates image code semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when querying images: "json: cannot unmarshal string into Go struct field .images of type bool"

8 participants