Skip to content

Conversation

@m41denx
Copy link
Contributor

@m41denx m41denx commented Oct 27, 2025

Basically I use Pelican with Postgres (I know it's not recommended, but still) and on New Mount page in admin area I get following error:

SQLSTATE[42883]: Undefined function: 7 ERROR: could not identify an equality operator for type json 
LINE 1: select distinct "eggs".* from "eggs" left join "mountables" ... ^ 
(Connection: pgsql, SQL: select distinct "eggs".* from "eggs" left join "mountables" on "eggs"."id" = "mountables"."mountable_id" order by "eggs"."name" asc limit 50) 
(View: /var/www/html/vendor/filament/forms/resources/views/components/select.blade.php) 
(View: /var/www/html/vendor/filament/forms/resources/views/components/select.blade.php) 
(View: /var/www/html/vendor/filament/forms/resources/views/components/select.blade.php) 
(View: /var/www/html/vendor/filament/forms/resources/views/components/select.blade.php) 
(View: /var/www/html/vendor/filament/forms/resources/views/components/select.blade.php)

I'm not sure if this the correct solution, but I opted for selecting only distinct id and name to prevent Postgres from comparing JSON columns

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

📝 Walkthrough

Walkthrough

Replaced the eggs relationship Select in MountResource.php with a three-argument call that provides a query callback selecting only eggs.id and eggs.name (and ordering by eggs.name), avoiding Postgres DISTINCT issues on JSON fields and ensuring deterministic ordering.

Changes

Cohort / File(s) Summary
Query customization for eggs relationship
app/Filament/Admin/Resources/Mounts/MountResource.php
Replaced Select::relationship('eggs', 'name') with Select::relationship('eggs', 'name', fn (Builder $query) => $query->select(['eggs.id', 'eggs.name'])). Added comment explaining selection of non-JSON fields and ensured ordering to avoid DISTINCT-on-JSON errors.

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Fix weird postgres behavior when selecting mounts" is directly related to the main change in the pull request. The changeset modifies how the eggs relationship is selected in MountResource specifically to resolve a PostgreSQL error that occurs during the selection process. While the word "weird" is somewhat informal, it is sufficiently specific to convey that a PostgreSQL-specific issue is being addressed, and a teammate reviewing the commit history would understand that this fixes a problem with selecting mounts in PostgreSQL.
Description Check ✅ Passed The description is clearly related to the changeset and provides meaningful context about the issue being solved. It explains the specific PostgreSQL error encountered, includes the problematic SQL query, and describes the rationale for the fix—preventing PostgreSQL from attempting to compare JSON columns by selecting only distinct id and name fields. The description is substantive and directly tied to the code changes made in the pull request, making it relevant and informative.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rmartinoscar rmartinoscar marked this pull request as draft October 28, 2025 00:43
@m41denx
Copy link
Contributor Author

m41denx commented Oct 28, 2025

I've just deployed this fix to my server and now I can create mounts, BUT NOT EDIT THEM
image

I'll investigate this issue further

@m41denx
Copy link
Contributor Author

m41denx commented Oct 28, 2025

Yes, that fixed the issue. I couldn't find any more issues with postgres and mounts, all CRUD operations seem to work

@m41denx m41denx marked this pull request as ready for review October 28, 2025 07:21
Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/Filament/Admin/Resources/Mounts/MountResource.php (1)

165-166: Fix correctly addresses the PostgreSQL DISTINCT issue.

The query callback restricting selection to only id and name prevents PostgreSQL from attempting DISTINCT operations on JSON columns, which resolves the reported SQL error. This is the minimal change needed since Filament's Select component only requires these two fields.

Optional: Consider using "PostgreSQL" instead of "Postgres" in the comment.

For consistency with the formal product name, consider this minor wording update:

-                            // Selecting only non-json fields to prevent Postgres from choking on DISTINCT JSON columns
+                            // Selecting only non-json fields to prevent PostgreSQL from choking on DISTINCT JSON columns
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b18499c and 3a86713.

📒 Files selected for processing (1)
  • app/Filament/Admin/Resources/Mounts/MountResource.php (1 hunks)
🔇 Additional comments (1)
app/Filament/Admin/Resources/Mounts/MountResource.php (1)

170-170: No changes needed for the nodes relationship.

The nodes table contains only scalar column types (integers, strings, timestamps) with no JSON/JSONB columns. The PostgreSQL DISTINCT issue that affected the eggs relationship does not apply here. The nodes relationship at line 170 is correctly implemented.

@notAreYouScared notAreYouScared merged commit 5e3c22e into pelican-dev:main Oct 28, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants