Skip to content

fix(inventory): allow floating-point values for inventory item measurements - #16785

Open
coderlucifer wants to merge 1 commit into
medusajs:developfrom
coderlucifer:fix/inventory-item-float-measurements
Open

fix(inventory): allow floating-point values for inventory item measurements#16785
coderlucifer wants to merge 1 commit into
medusajs:developfrom
coderlucifer:fix/inventory-item-float-measurements

Conversation

@coderlucifer

Copy link
Copy Markdown

What

Allow inventory item measurement fields (weight, length, height, width) to store floating-point values like 0.1 or 4.5.

Fixes #16784

Why

PR #14762 aligned product and product-variant volumetric attributes to use model.float() (mapped to real in Postgres), but the inventory item model was not updated in that PR. It still uses model.number() which maps to an integer column, so values like 0.5 kg or 12.3 cm get truncated to whole numbers — both in the database and the admin dashboard create form (which used optionalInt validation).

How

Same approach as #14762, applied to the inventory item module:

  1. Data model (packages/modules/inventory/src/models/inventory-item.ts):
    Changed model.number() to model.float() for weight, length, height, and width.

  2. Database migration (packages/modules/inventory/src/migrations/Migration20260911000000.ts):
    ALTER COLUMN ... TYPE real USING ("column"::real) converts the four columns from int to real. Includes a reversible down() that reverts to int. Uses explicit USING cast as flagged in the fix(product, dashboard): align product and variant volumetric attributes data types #14762 review.

  3. Admin dashboard (packages/admin/dashboard/src/.../inventory-create-form/schema.ts):
    Changed form validation from optionalInt to optionalFloat so the create inventory item form accepts decimal input. The edit form already uses z.number().positive().optional() which accepts floats.

  4. Migration snapshot (.snapshot-medusa-inventory.json):
    Updated type from "integer" to "real" and mappedType from "integer" to "float" for all four fields.

No changes needed to API validators (z.number() already accepts floats) or TypeScript types (number already accepts floats).

Testing

@coderlucifer
coderlucifer requested a review from a team as a code owner September 11, 2026 08:16
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0224558

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 83 packages
Name Type
@medusajs/inventory Patch
@medusajs/dashboard Patch
@medusajs/medusa Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/admin-bundler Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/search Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/search-postgres Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/auth-oidc Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/instantsearch-adapter Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
create-medusa-app Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@medusa-os-bot

medusa-os-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

Thanks for the contribution! Initial automated review looks good.

The contributor adds support for floating-point values in the inventory item measurement fields (weight, length, height, width), aligning them with the product/variant models that were updated to use model.float() in an earlier change. All relevant layers are consistently updated: the data model switches from model.number() to model.float(), the database migration correctly uses ALTER COLUMN ... TYPE real USING ("column"::real) with a reversible down(), the MikroORM snapshot reflects the new type: real / mappedType: float, and the admin dashboard create-form schema switches from optionalInt to optionalFloat. The optionalFloat validator already exists in the validation library and enforces a non-negative constraint while accepting decimal input. The changeset is correctly included and formatted. No tests are added, but for a trivial column-type alignment bug fix this is within the range of accepted minor-fix omissions per project conventions. No security, performance, or correctness issues were found.

Triggered by: new PR opened

@e1himself

Copy link
Copy Markdown

@coderlucifer I suspect you didn't test this change manually.

Because the UI needs updating too. See #13863 for inspiration.

…ements

Change weight, length, height, width from integer to float on the inventory item model, matching the product module (fixed in medusajs#14762). Includes a database migration (int -> real), schema validation update (optionalInt -> optionalFloat), and adds step='any' to all measurement input fields in both create and edit forms so the browser allows decimal input (matching medusajs#13863).

Closes medusajs#16784
@coderlucifer
coderlucifer force-pushed the fix/inventory-item-float-measurements branch from 7e52850 to 0224558 Compare September 11, 2026 10:40
@coderlucifer

Copy link
Copy Markdown
Author

@coderlucifer I suspect you didn't test this change manually.

Because the UI needs updating too. See #13863 for inspiration.

Thanks for the catch @e1himself! You're right — I missed the UI layer.

I've now pushed an update that adds step="any" to all 8 measurement input fields across both forms:

  • Create form (inventory-create-form.tsx) — width, length, height, weight
  • Edit form (edit-item-attributes-form.tsx) — height, width, length, weight

This matches what was done in #13863 for the product attributes. Without step="any", the browser's native <input type="number"> validation rejects decimal values since it defaults to step="1".

The full fix now covers all three layers:

  1. Model: model.number()model.float()
  2. Migration: ALTER COLUMN ... TYPE real USING ("col"::real)
  3. Schema: optionalIntoptionalFloat
  4. UI: step="any" on all measurement inputs

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.

[Bug]: Inventory item measurements attributes do not allow floating point values

2 participants