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

Service template picture #18689

Merged
merged 2 commits into from Apr 29, 2019
Merged

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Apr 25, 2019

We're not updating service templates with pictures correctly (or updating them) because the template is expecting a picture and instead gets a hash of options to create the picture. (Sorry, LJ! I'm a doofus and https://github.com/ManageIQ/manageiq/pull/18674/files#diff-9257fff45a7d1258305c9a6b7d15e322R519 doesn't actually update the picture, funnily enough.)

It's the actual working update code for #18674.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1683723

@d-m-u
Copy link
Contributor Author

d-m-u commented Apr 25, 2019

@miq-bot assign @jrafanie
@miq-bot add_label bug
@miq-bot add_label hammer/yes

@d-m-u d-m-u force-pushed the service_template_picture branch 4 times, most recently from eef4819 to 3381b26 Compare April 26, 2019 12:37
if value
super unless value.kind_of?(Hash)

super(create_picture(value))
Copy link
Member

Choose a reason for hiding this comment

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

How does this instance method get to the class method?

Copy link
Member

Choose a reason for hiding this comment

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

As such, are there specs for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it's calling the dynamic method for the singular association... My only concern is if self hasn't been persisted yet. I don't know if create_picture would require it be saved first. I don't know. You might have to call Picture.new or something like that and pass that to super. 🤷‍♂

Copy link
Member

Choose a reason for hiding this comment

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

irb(main):007:0* st = ServiceTemplate.create!(:name => "blah")
   (0.2ms)  BEGIN
  User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE ("users"."id" BETWEEN $1 AND $2) AND "users"."userid" IS NULL LIMIT $3  [["id", 0], ["id", 999999999999], ["LIMIT", 1]]
  User Inst Including Associations (0.0ms - 0rows)
  SQL (6.2ms)  INSERT INTO "service_templates" ("name", "guid", "created_at", "updated_at", "miq_group_id", "tenant_id", "internal", "service_type", "generic_subtype") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["name", "blah"], ["guid", "cb823fc0-8b3f-40a3-b195-ee71866d7539"], ["created_at", "2019-04-29 19:26:38.584945"], ["updated_at", "2019-04-29 19:26:38.584945"], ["miq_group_id", 1], ["tenant_id", 1], ["internal", "f"], ["service_type", "atomic"], ["generic_subtype", nil]]
   (0.4ms)  COMMIT
=> #<ServiceTemplate id: 44, name: "blah", description: nil, guid: "cb823fc0-8b3f-40a3-b195-ee71866d7539", type: nil, service_template_id: nil, options: {}, created_at: "2019-04-29 19:26:38", updated_at: "2019-04-29 19:26:38", display: nil, evm_owner_id: nil, miq_group_id: 1, service_type: "atomic", prov_type: nil, provision_cost: nil, service_template_catalog_id: nil, long_description: nil, tenant_id: 1, generic_subtype: nil, deleted_on: nil, internal: false, zone_id: nil>

irb(main):009:0> st.create_picture(:content => "iVBORw0KGgoAAAAN", :extension => "jpg")
   (0.2ms)  BEGIN
  SQL (3.6ms)  INSERT INTO "pictures" ("resource_id", "resource_type", "content", "extension", "md5") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["resource_id", 44], ["resource_type", "ServiceTemplate"], ["content", "<16 bytes of binary data>"], ["extension", "jpg"], ["md5", "4617a55a374175d8d7479071f41db6c7"]]
   (0.4ms)  COMMIT
  Picture Load (1.0ms)  SELECT  "pictures".* FROM "pictures" WHERE "pictures"."resource_id" = $1 AND "pictures"."resource_type" = $2 LIMIT $3  [["resource_id", 44], ["resource_type", "ServiceTemplate"], ["LIMIT", 1]]
  Picture Inst Including Associations (0.1ms - 1rows)
=> #<Picture id: 15, resource_id: 44, resource_type: "ServiceTemplate", content: "iVBORw0KGgoAAAAN", extension: "jpg", md5: "4617a55a374175d8d7479071f41db6c7">

Kewl!

👍

Copy link
Member

Choose a reason for hiding this comment

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

For what it is worth, this fails if the picture exists first:

picture = Picture.create(:content => "foo", :extension => "jpg")
ServiceTemplate.create(:name => "foo", :picture => picture)

Currently used like this in specs:

https://github.com/ManageIQ/manageiq-api/blob/f12cf95d/spec/requests/service_templates_spec.rb#L16-L22

@d-m-u d-m-u force-pushed the service_template_picture branch 3 times, most recently from aa0f0d1 to 94b2f91 Compare April 26, 2019 15:53
@@ -403,6 +399,14 @@ def provision_request(user, options = nil, request_options = {})
result[:request]
end

def picture=(value)
if value
super unless value.kind_of?(Hash)
Copy link
Member

@jrafanie jrafanie Apr 29, 2019

Choose a reason for hiding this comment

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

I like how we can choose which format we want to use and we can deprecate the other easily. The problem with rails create_picture magic is it makes passing around hashes easier to deal with. I think we still want picture= to accept a Picture object in the future, but this can be a bridge to doing that.

@miq-bot
Copy link
Member

miq-bot commented Apr 29, 2019

Checked commits d-m-u/manageiq@75d8e0b~...c617cbc with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@jrafanie jrafanie merged commit 5f37ae7 into ManageIQ:master Apr 29, 2019
@jrafanie jrafanie added this to the Sprint 110 Ending Apr 29, 2019 milestone Apr 29, 2019
@d-m-u d-m-u deleted the service_template_picture branch April 29, 2019 20:22
simaishi pushed a commit that referenced this pull request Apr 29, 2019
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit cebab02f23077496a12913e5ed97026c72c23443
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Mon Apr 29 16:21:33 2019 -0400

    Merge pull request #18689 from d-m-u/service_template_picture
    
    Service template picture
    
    (cherry picked from commit 5f37ae764a60ae0985235d4f0b70a791b5b43afa)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702479

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

Successfully merging this pull request may close these issues.

None yet

6 participants