Skip to content

Handle persisted empty Point arrays - #77

Open
dblock wants to merge 1 commit into
mongoid:masterfrom
dblock:dblock/empty-point
Open

dblock wants to merge 1 commit into
mongoid:masterfrom
dblock:dblock/empty-point

Conversation

@dblock

@dblock dblock commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #55.

Reading a Point stored as [] currently calls Point.new without coordinates and raises ArgumentError. Return nil for that empty stored value, matching existing empty-array assignment behavior. Reading does not rewrite the database, and malformed nonempty coordinates retain their existing error behavior.

Add regression coverage for raw persisted empty arrays, replacing them with valid coordinates, explicitly clearing them, and preserving valid coordinates including zero and altitude. Update the README and changelog.

Validation

Focused Point specs and RuboCop pass.

context 'with an empty array stored in the database' do
let(:bar) do
document = Bar.create!(location: [1, 2])
Bar.collection.find(_id: document.id).update_one('$set' => { location: [] })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [82/80]


require 'spec_helper'

describe Mongoid::Geospatial::Point, '.demongoize' do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Metrics/BlockLength: Block has too many lines. [31/25]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think the bot is conflicting with rubocop rules - I propose leaving rubocop.

@coveralls

coveralls commented Oct 15, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 98.596% (+0.004%) from 98.592% — dblock:dblock/empty-point into mongoid:master

@dblock
dblock requested a review from nofxx October 15, 2026 12:33
@dblock
dblock force-pushed the dblock/empty-point branch from b687212 to fc0ea36 Compare October 15, 2026 12:45
context 'with an empty array stored in the database' do
let(:person) do
document = Person.create!(location: [1, 2])
Person.collection.find(_id: document.id).update_one('$set' => { location: [] })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [85/80]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock
dblock force-pushed the dblock/empty-point branch from fc0ea36 to 028b386 Compare October 18, 2026 14:57
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.

Empty arrays persisted in database get demongoized and throw ArgumentError

3 participants