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

Fix: convert string representation of sizes to numbers when generating SQL for expression #18649

Merged

Conversation

yrudman
Copy link
Contributor

@yrudman yrudman commented Apr 10, 2019

Issue:
New Expression editor allows to select unit of measurement for some field (like MB, GB, etc...) and those units saved in expression. Example: {"<"=>{"field"=>"ManageIQ::Providers::InfraManager::Vm-allocated_disk_storage", "value"=>"2.gigabytes"}}
However, during SQL generation "2.gigabytes" was not converting to Integer:

[ActiveRecord::StatementInvalid]: PG::InvalidTextRepresentation:
ERROR:  invalid input syntax for type numeric: "2.gigabytes"
LINE 1: ...ares"."vm_or_template_id" = "vms"."id" LIMIT 1) < '2.gigabyt...
                                                             ^
: SELECT "vms".*, (SELECT  "hardwares"."memory_mb" FROM "hardwares"
WHERE "hardwares"."vm_or_template_id" = "vms"."id" LIMIT 1) AS mem_cpu FROM "vms"
WHERE "vms"."type" IN ('ManageIQ::Providers::InfraManager::Vm', 'VmXen', 
'ManageIQ::Providers::Kubevirt::InfraManager::Vm',
 'ManageIQ::Providers::Redhat::InfraManager::Vm',
'ManageIQ::Providers::Microsoft::InfraManager::Vm',
'ManageIQ::Providers::Vmware::InfraManager::Vm') AND "vms"."template" = $1
AND ((SELECT  (SELECT SUM("disks"."size") FROM "disks"
WHERE "hardwares"."id" = "disks"."hardware_id") FROM "hardwares"
WHERE "hardwares"."vm_or_template_id" = "vms"."id" LIMIT 1) < '2.gigabytes') 

FIX:
Convert human representation of sizes to Integer

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

@miq-bot add-label bug, reporting, hammer/yes

@yrudman yrudman force-pushed the convert-human-sizes-to-bytes-in-expression branch 2 times, most recently from 18d1ccc to 3305ecc Compare April 10, 2019 23:34
# check operands to see if they can be represented in sql
unless sql_supports_atom?(exp)
if sql_supports_atom?(exp)
convert_bytes_untits(exp) if %w[= != <= >= >].include?(operator)
Copy link
Member

Choose a reason for hiding this comment

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

Small typo on method name. Should be convert_bytes_units

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gtanzillo renamed to slightly more descriptive - convert_size_in_units_to_integer

@yrudman yrudman force-pushed the convert-human-sizes-to-bytes-in-expression branch from 3305ecc to 77b8238 Compare April 12, 2019 21:12
@yrudman yrudman force-pushed the convert-human-sizes-to-bytes-in-expression branch from 77b8238 to a11845f Compare April 15, 2019 16:00
@miq-bot
Copy link
Member

miq-bot commented Apr 15, 2019

Checked commits yrudman/manageiq@a84aac1~...a11845f 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. 🍰

@yrudman yrudman changed the title [WIP] Fix: convert string representation of sizes to numbers when generating SQL for expression Fix: convert string representation of sizes to numbers when generating SQL for expression Apr 15, 2019
@miq-bot miq-bot removed the wip label Apr 15, 2019
@gtanzillo gtanzillo added this to the Sprint 110 Ending Apr 29, 2019 milestone Apr 18, 2019
@gtanzillo gtanzillo merged commit db74833 into ManageIQ:master Apr 18, 2019
@yrudman yrudman deleted the convert-human-sizes-to-bytes-in-expression branch April 18, 2019 17:57
simaishi pushed a commit that referenced this pull request Apr 22, 2019
…n-expression

Fix: convert string representation of sizes to numbers when generating SQL for expression
(cherry picked from commit db74833)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702077
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit 0046a864ffaa0284acd7c73fe338933ea1a1fd8e
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Thu Apr 18 13:52:14 2019 -0400

    Merge pull request #18649 from yrudman/convert-human-sizes-to-bytes-in-expression
    
    Fix: convert string representation of sizes to numbers when generating SQL for expression
    (cherry picked from commit db748333c85f0ed4c3100652976f92a5ef458f23)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702077

@yrudman
Copy link
Contributor Author

yrudman commented Apr 24, 2019

@miq-bot add-label changelog/yes

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.

4 participants