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

Fixes #38272 - Use .presence for ip6 address #10470

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

ShimShtein
Copy link
Member

@@ -99,6 +99,6 @@ def validate_ssh_provisioning

def provision_host
# usually cloud compute resources provide IPs but virtualization do not
provision_interface.ip6 || provision_interface.ip || provision_interface.fqdn
Copy link
Member

Choose a reason for hiding this comment

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

You can use .ip6.presence to force an empty string to nil and keep ||

Copy link
Member Author

Choose a reason for hiding this comment

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

changed, thanks!

@ShimShtein ShimShtein force-pushed the fix_empty_string_ip6 branch from cc0ef10 to 9c13f1a Compare March 6, 2025 11:41
@ShimShtein ShimShtein changed the title Fixes #38272 - Use present? instead of || for ip6 address Fixes #38272 - Use .presence for ip6 address Mar 6, 2025
@amolpati30
Copy link

@ShimShtein
I tested the issue using this patch and confirm that it is working as expected.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Something I didn't check before, but this was introduced in 820308f and https://projects.theforeman.org/issues/38057 is fixed in 3.14. That means you can use Refs #38057 here if we cherry pick it to 3.14 before GA.

I see you also used provision_interface.ip.presence which makes me think it never could reach provision_interface.fqdn to begin with. That part was introduced in 8397b3c but looks like that was flawed to begin with. That could be an argument for its own issue.

What do you think?

@ShimShtein
Copy link
Member Author

ShimShtein commented Mar 9, 2025

Well, I think it's a bit semantic, and in this case I would leave it as a separate issue.
I went over the references to ip6 to make sure that we're not expecting nil in case of a missing value.

It does make me wonder though, why should we use an empty string for IP values anyway? If the value is missing, it should be nil. If I had some spare time on my hands, I would look into making sure it's either IP or nil.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

It does make me wonder though, why should we use an empty string for IP values anyway? If the value is missing, it should be nil. If I had some spare time on my hands, I would look into making sure it's either IP or nil.

I know Django generally has the rule that you shouldn't use nullable strings because now there are 2 representations for an empty value. They generally recommend empty strings for empty. Perhaps it helps a bit that in Python an empty string is false where in Ruby it's true.

Do you know what sort of guidelines Rails provides here?

I'm ok merging this because it fixes a regression in 3.14 (so we need to merge it this week) and since it does make the change to .ip as well I think a separate issue makes sense.

Could you please make sure the commit message and PR title accurately describe the chosen solution? After that ACK.

We cannot use regular `||` method on `ip6` and `ip` fields,
since the value can be an empty string.
@ShimShtein
Copy link
Member Author

Synced commit and PR

@ekohl ekohl merged commit cd26ede into theforeman:develop Mar 11, 2025
31 checks passed
@stejskalleos
Copy link
Contributor

Cherry-pick: #10475

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

Successfully merging this pull request may close these issues.

4 participants