Skip to content

Fix: don't match enum columns as spatial#433

Open
modosc wants to merge 1 commit intorgeo:masterfrom
treadinc:fix-enum-types
Open

Fix: don't match enum columns as spatial#433
modosc wants to merge 1 commit intorgeo:masterfrom
treadinc:fix-enum-types

Conversation

@modosc
Copy link

@modosc modosc commented Jul 24, 2025

fixes #432

@modosc modosc marked this pull request as ready for review July 24, 2025 17:18
Comment on lines +214 to +215
SpatialModel.lease_connection.create_enum(:point_type, ["point", "line_string", "polygon"])
SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t|
Copy link
Member

Choose a reason for hiding this comment

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

Is it properly cleanup afterwards ? If so, how ?

Copy link
Author

Choose a reason for hiding this comment

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

i don't know - i copied this from the other examples, can you point me to where any explicit cleanup happens?

Comment on lines +216 to +218
t.column "latlon", :st_point, srid: 3785
t.column "latlon_geo", :st_point, srid: 4326, geographic: true
t.column "default_latlon", :st_point, srid: 0, default: "POINT(0.0 0.0)"
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have these ?

Copy link
Author

Choose a reason for hiding this comment

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

these were copied from create_model below, happy to remove them if you think it's necessary.

@@ -12,7 +12,9 @@ def initialize(name, default, sql_type_metadata = nil, null = true,
serial: nil, generated: nil, spatial: nil, identity: nil)
@sql_type_metadata = sql_type_metadata
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
if spatial
if sql_type_metadata.type == :enum
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should not be there if we are handling enums. Otherwise this also means that sql_type_metadata is set for every column, spatial or not.

I believe we should verify how the step before that one is working to make sure this is the correct place (e.g. who is initialising this)

Copy link
Author

Choose a reason for hiding this comment

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

afaict this is by design.

this is initialized from #new_column_from_field which overrides the rails implementation and returns a SpatialColumn (instead of a PostgreSQL::Column) for all columns.

i'm not sure what would happen if some fields were one type and some were another but it seems out of scope for this pr.

@modosc modosc requested a review from BuonOmo November 22, 2025 20:21
@BuonOmo
Copy link
Member

BuonOmo commented Nov 24, 2025

@modosc, I did not forget the PR. I am prioritizing rails 8.1 compatibility though.

@modosc
Copy link
Author

modosc commented Nov 24, 2025

@modosc, I did not forget the PR. I am prioritizing rails 8.1 compatibility though.

no worries - lmk if there's anything i can do to help on that side.

@BuonOmo
Copy link
Member

BuonOmo commented Jan 8, 2026

Hey @modosc, could you update your PR and add an entry to the History.md file please ? I also am not 100% sure about how this is handled yet. May I work on it as well or would you rather keep ownership ? If I may, I'd like access to your repo as a contributor! In any case, I'll work on the activerecord-cockroachdb-adapter version of it now hence we'll be able to compare in the end :)

@modosc
Copy link
Author

modosc commented Jan 13, 2026

@BuonOmo i just rebased it. i can't give you access because it's originating from my work org.

@BuonOmo
Copy link
Member

BuonOmo commented Jan 14, 2026

Ok so what we need:

  • History entry
  • Correct test lifecycle (EDIT: we clearly see how test lifecycle is messed up in tests results)

What I'm unsure about:

  • the place where the fix is made (we're already setting geometry related instance variables beforehand, do we want to? also the complexity of the method is becoming huge)

Let's work on that together then :)

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.

geometric_type false positive when enum name matches pattern

2 participants

Comments