Skip to content

fix: orderable collection not working when collection has group or tab field #12129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kristian240
Copy link
Contributor

@kristian240 kristian240 commented Apr 16, 2025

What?

There is an issue when Payload uses postgresAdapter. If collection is orderable and there is a field that is type of group or tab.

I cannot replicate the issue in e2e tests and mongoDB but if I use Postgres the issue is there; can you shed some light why is that? Also, how can I run e2e with Postgres db?

Why?

After the group and tab fields are transformed, there is a piece of code that deletes _order prop on the root of the document, instead, we should delete _order in that field.

How?

Now, we delete _order in ref[refKey] instead on the root document - ref.

@GermanJablo GermanJablo self-requested a review April 21, 2025 13:55
@GermanJablo GermanJablo self-assigned this Apr 21, 2025
@maximseshuk
Copy link
Contributor

This PR should fix this issue #12143

@GermanJablo
Copy link
Contributor

Thanks for the contribution.

This PR does indeed fix the bug described with the group or tab field, which I've been able to reproduce, but it's not related to issue #12143, which is due to an incorrect migration, as I explained here.

For now, e2e tests only run on MongoDB, which is why the bug wasn't properly detected. If you do an integration test, it will run with Postgres in CI. A nice thing to have, although not strictly necessary in this case, as I reproduced the issue and the solution manually.

The only impediment to merging this is that there's a small TypeScript error blocking the build. Can you take a look at it?

@kristian240
Copy link
Contributor Author

kristian240 commented Apr 24, 2025

Hey @GermanJablo! I fixed the TS issue and found out that my change break the draft ordering. I implemented a fix in 7592724 but I'd love to hear your opinion. Tbh, I'm not a fan of hardcoded value.


Also, seems like CI job with builds are failing due to this error

cloudflare:sockets
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.

Can you help me with the issue since I don't think this issue is caused with this PR.

@GermanJablo
Copy link
Contributor

You know what? I just tried to reproduce the bug again and couldn't. Reproduction steps:

  1. I reverted the changes in packages/drizzle/src/transform/read/traverseFields.ts
  2. I kept the meta field of type group in test/sort/collections/Orderable/index.ts
  3. I run pnpm dev:postgres sort
  4. I went to http://localhost:3000/admin/collections/orderable and was able to reorder without any issues.

I think I saw an error the first time I tried that. But now I'm wondering, maybe I was confused by another configuration. The first step to moving forward with a solution is to be able to reproduce the problem. So if you could walk me through the steps, that would be great.

I have a few observations about the current attempted fix, but first, I want to make sure there really is a bug here.

P.S: Yes, ignore the current error in CI. It's not related to this PR. We're investigating it.

@kristian240
Copy link
Contributor Author

Hey @GermanJablo can you take another look, seems like @joedawson made the repo where issue does occur

@GermanJablo
Copy link
Contributor

Hi @kristian240, that issue mentions:

I've seen my previous issue mentioned in PR #12129 and I did originally have my hunch set on this being my issue - but even without tabs I am getting my mentioned issues.

I've opened the repo, and I don't see collections having groups or tabs, so I don't think this PR describes a reproducible issue yet.

@joedawson
Copy link

Would the SEO fields be considered a group in my issue?

@DanRibbens
Copy link
Contributor

I don't think this PR describes a reprod

Yes the SEO plugin creates a group field with the name meta.

@GermanJablo
Copy link
Contributor

Yes, I just checked. It's very likely the same issue then. I'm still debugging.

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.

5 participants