Problem/Motivation

Float fields are confusing unless you understand what a float is. If you create a float field on a node, I have no idea how to explain to a user that 10000.1 and 3.141 are stored without alteration but 1234.5678 is stored as 1234.57. #2542132: Drupal\field\Tests\Number\NumberFieldTest fails on SQLite suggest making all float fields doubles so they can store much large numbers but even with 8-byte storage float fields can be confusing.

Proposed resolution

Mark the float number and list (float) fields as 'no_ui' so they no longer show up for site builders.

Custom/contrib module developers will still be able to add the fields, either by programatically creating the configuration or using base/bundle field info hooks, and sites with the fields already configured will continue to work.

Remaining tasks

Issue fork drupal-2542760

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott’s picture

Title: Drupal\field\Tests\Number\NumberFieldTest fails on SQLite » Move Float fields to contrib
plach’s picture

Component: sqlite db driver » number.module

I guess this is a better component :)

dawehner’s picture

Yeah I totally think that float not stored as doubles are pointless.

Not that we care, but the myth that floats are less to compute is actually wrong these days. CPUs use doubles native and need conversion before doing anything with floats.

jibran’s picture

I think we need someone from Drupal commerce to comment on this. I only see price field as a float.

berdir’s picture

No, prices are never floats. Decimal yes, but not float.

dawehner’s picture

Price should be a decimal field.

amateescu’s picture

They are using the float data type, not the float field type: https://github.com/commerceguys/commerce/blob/8.x-2.x/modules/price/src/...

yched’s picture

I'm all for moving floats out of core, if that's something we're still ok with at this point.

As far as I can remember, floats went into D7 mostly because they were part of the cck pack. I agree that they mostly add confusion when choosing your field type, while the actual use cases are very non-80%. They are also kind of half-baked, for the same reason.

We'd need a volunteer to maintain them in contrib though :-)

webchick’s picture

I'm fine with this (fewer choices in that drop-down of DOOOOM the better), although not sure 100% why we're discussing it now.

webchick’s picture

...nor why it's major? I guess because there's a major bug with the Float upgrade path?

alexpott’s picture

Priority: Major » Normal

We're discussing it now because sqlite stores floats differently from sqlite and postgres. It is major because I used the clone button.

bojanz’s picture

Prices must never be floats. The linked code is temporary and embarrassing.
In general, float fields should be used very carefully. You almost always want a decimal instead.

+1 to moving to contrib.

catch’s picture

The fact that commerce is temporarily using the wrong datatype is a very good reason to move these to contrib.

@yched I think we should be prepared to move things out without a maintainer stepping up. Especially when it's something we're trying to remove from core because we want to discourage people from using it. Doesn't help people that are already using it of course, and hard to get any actual data on that.

alexpott’s picture

One complication is that we only have ListFloatItem and not ListDecimalItem :(

yched’s picture

we only have ListFloatItem and not ListDecimalItem

Oh crap, that's unfortunate. I don't even think I remember why that happened, we're probably talking CCK D5 :-/

Well, I guess turning ListFloatItem into ListDecimalItem would not be too hard... It does add to the "disruption" part though.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Issue summary: View changes

Updating the IS with some details.

webchick’s picture

Version: 8.6.x-dev » 9.1.x-dev

This would have to happen in 9.1 now, for deprecation in Drupal 10, I think...

Although, just musing... rather than moving wholesale to contrib, do we instead want to make Float into a proper Decimal field, so it more cleanly matches user expectations? (e.g. I would expect a "Price" field to be something that 50%+ of sites would expect to be able to do with core, and would be very surprised when I got chastised by @bojanz ;) for choosing the one option in core that seemed to fit.)

jhedstrom’s picture

Issue summary: View changes
StatusFileSize
new68.62 KB

do we instead want to make Float into a proper Decimal field

I think we already have a decimal field (it might not be proper), but this got me thinking, instead of moving to contrib, we could move 'float' to a separate module within core, then write an update hook to enable that module for any site that actually has float fields, and then disable the module by default on new installs. That way the decimal number would remain in the selection, but the confusing float would not.

once float was in it's own module, a proper 'double' precision type could also be added, which would avoid the confusion many have with float, but not bloat the default field type selector unnecessarily...

The above approach could presumably go into 8.x, 9.x, etc, given a proper change notice...

catch’s picture

Version: 9.1.x-dev » 9.0.x-dev

We we would need to do #24 (or very close) if we move the module to contrib too, so splitting it out is a good step regardless of where it ends up eventually. Moving back to 9.0.x.

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev
Issue tags: +Needs product manager review

Interesting idea. This would need product signoff. (#23 isn't so much a signoff as feedback/review.) At this point this would definitely be deprecate-in-D9-minors, remove-in-D10. So 9.1.x.

maxilein’s picture

All you are saying is that drupal does not have proper number and calculation support until 9.1.?!
Are you sure?!

A year ago I had problems with the decimal field. It would not aggregate (if I remember correctly). So I moved them all to floats in order to be able to make simple calculations with decimals.
It worked up to some 8.x release very well. I realized with 8.8.5 (maybe the issue existed earlier - I couldn't say) that float is broken.

So the only number fields that can be used reliably are integers?!
8.8.5 is just a beta?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

While this will need an upgrade path, it is not yet tied to a specific version.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Issue summary: View changes

I just created a number field on a site, and got the three options for integer, decimal, and float. Nearly opened a new issue to remove float then found this one.

Updated the issue summary with a proposed plan. The plugin is defined in core/lib, not in any module. I think the simplest way with this might be to create a new float module directly in contrib, and deprecate the core decimal plugin directly in core - i.e. without an interim step of moving the field to a module in core. This is because we don't only want to remove it from core but also we want to discourage people from using it on new sites.

If we try to move it to a module within core before moving it out, we'll need to enable that module on sites using the float field type, which means an upgrade path etc. - better to let those sites manually add a contrib module when they do a major upgrade (or any time before a major upgrade once the module is available).

catch’s picture

Issue tags: -Upgrade path

Removing the upgrade path tag because I think we can do this without an actual update - just a module for sites to add from contrib if they use the field.

catch’s picture

When updating the issue summary, I forgot we don't have #3039240: Create a way to declare a plugin as deprecated yet. Also if we only deprecate the plugin, it will still be in the UI for all Drupal 11 sites.

So it might be better to go the module route in core after all, this would look like:

1. Move the plugin and any test coverage to a new 'Float field' module.

2. Add an upgrade path, in system module, to install the module on any site that's using the float field.

3. Immediately/asap mark that module deprecated and do the other steps to move it to a contrib module.

lauriii’s picture

I went through different contrib use cases for floats and I didn't really find good examples where float would be used correctly as a bundle field. There are examples of valid use cases where float is used as a base field. This doesn't mean someone couldn't be using it for the right reasons as a bundle field but by nature float is probably something that would be more likely to be used as base field for use cases like computations.

If float field type is a minimal maintenance feature for us, I'm wondering if we should keep float as a field type in core but start by marking it as no_ui: true? A contrib module could be then be added to add it to the Field UI for those that need it there.

maxilein’s picture

I like the no_ui idea!

catch’s picture

Title: Move Float fields to contrib » Mark float and list (float) field types as no_ui
Issue tags: +Needs issue summary update

Let's try no_ui here. The main issue is the UX issue presenting these as choices in the field UI, saves us having to do the full module and deprecation route and doesn't prevent us from doing that later if there's a new reason to.

lauriii’s picture

Removing the product review tag based on #38. Removing the subsystem maintainer review tag since removing the field type from UI is much less invasive than moving it to contrib.

catch’s picture

Status: Active » Needs work

Pushed a two-line MR to see what breaks, if anything.

catch’s picture

Status: Needs work » Needs review

lol, two more lines necessary to get things green, so four lines in total.

That's a lot easier than factoring out to a module and moving to contrib!

catch’s picture

Issue summary: View changes
alexpott’s picture

Issue tags: +Needs change record

Very nice - I think with the addition of a CR we are good to go here.

catch’s picture

Added a change record and updated the issue summary.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Perfect.

  • lauriii committed b23f4270 on 11.x
    Issue #2542760 by catch, jhedstrom, alexpott, webchick, dawehner, yched...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed b23f427 and pushed to 11.x. Thanks!

berdir’s picture

I agree that this is a very rarely used feature, but it is sometimes used, http://codcontrib.hank.vps-private.net/search?text=field_type%3A%20float... has 3 pages of results (quite a lot are just tests). default config of course still works, just linked to that for use cases.

Unlike an optional module that non-developers can install, the no_ui flag requires that you implement an alter hook to be able to still add them through the UI.

As a compromise, I added an untested example hook to revert this, if someone creates a module for doing that they can share it there.

lauriii’s picture

Not mentioned here but we discussed on Slack that it would be simple to create a module for this. We could add that to the CR in case that someone wants to create that.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Amending attribution.

xmacinfo’s picture

@renat created a module (code is still missing as I write this) to reenable Number Float:

https://www.drupal.org/project/reenable_number_float

The module description makes it a good case on showing the Number Float again, instead of hiding it under the carpet.

renat’s picture

@xmacinfo Thanks for surfacing this! The code has now been added to the referenced module to re‑enable Number (float).

I do agree that the decimal field type is almost always preferable to float—provided we can actually make decimals work by resolving issue #2230909.

Given the number of core contributors and maintainers following this thread, would it make sense to open a focused follow‑up? Alternatively, could a respected community member define the absolute minimal requirements needed to commit the fix for #2230909 so we can finally move it forward? This is a triaged, core‑major issue that has been open for 11 years, leaves the decimal field type barely usable in practice, and has had a working patch for years that keeps stalling over nice‑to‑haves rather than must‑haves. Probably the priority should be to make the decimal field operational now; and anything beyond what is strictly necessary for this patch should go into a follow‑up?