Skip to content
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

fix: Prefix class names with Pagy module to prevent collisions #726

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

LuukvH
Copy link
Contributor

@LuukvH LuukvH commented Jul 29, 2024

This commit updates the code to prefix certain class names with the Pagy module name. The change is necessary to prevent potential collisions with class names defined in Rails applications.

These adjustments ensure that the Pagy pagination library operates correctly without interfering with other classes that might exist within the application namespace. The revised code now properly isolates Pagy-specific classes, enhancing compatibility and stability

@ddnexus
Copy link
Owner

ddnexus commented Jul 29, 2024

Thank you @LuukvH. Admittedly, the omissions are a bit pagy-centric 😁.

@LuukvH
Copy link
Contributor Author

LuukvH commented Jul 31, 2024

@ddnexus I am not sure why this test is failing. Doesn't seem to relate to my changes? Could you point me in the correct direction, then i can try to fix it.

@ddnexus
Copy link
Owner

ddnexus commented Aug 1, 2024

Hi @LuukvH , thank you for your persistence.

Please, keep your PR branch rebased on master. That will take care of the necessary updates that make your branch fail (not your code fault)

@ddnexus
Copy link
Owner

ddnexus commented Aug 3, 2024

The change is necessary to prevent potential collisions with class names defined in Rails applications.

@LuukvH I've tried to verify that there would indeed exists a collision, but I couldn't reproduce any of such collisions. Please, could you use any playground app to reproduce it?

@LuukvH
Copy link
Contributor Author

LuukvH commented Aug 19, 2024

@ddnexus Sorry, i needed some time to make the example.
You can find it here: https://github.com/LuukvH/pagy_collision_example

Just did a minimal setup with pagy. And defined a Calendar module: https://github.com/LuukvH/pagy_collision_example/blob/main/app/models/calendar.rb inside the app. As a result pagy is crashing since for example Calendar::Unit is not defined.
See the rspec run: https://github.com/LuukvH/pagy_collision_example/actions/runs/10454068661

I hope this offers you enough context.

@ddnexus
Copy link
Owner

ddnexus commented Aug 25, 2024

@LuukvH ... Thanks for your example app, but we need a modified playground app to reproduce - as requested in my previous message. I tried to add a bare Calendar model in the calendar.ru app, but - as i reported before - it works.

You can see it here. Please, modify that app to make it fail, so finding out the problem will be trivial.

You can read the playground apps doc for a quick way to try and develop it.

Thank you.

@LuukvH LuukvH force-pushed the master branch 5 times, most recently from f0194bf to 99bc0ba Compare August 26, 2024 13:58
@LuukvH
Copy link
Contributor Author

LuukvH commented Aug 26, 2024

@ddnexus i changed the rails playground app as a breaking example. The calendar one is the wrong place to do it, since there Calendar::Unit is actually defined.

@ddnexus
Copy link
Owner

ddnexus commented Aug 26, 2024

@ddnexus i changed the rails playground app as a breaking example. The calendar one is the wrong place to do it, since there Calendar::Unit is actually defined.

Where can I find the failing app?

@LuukvH
Copy link
Contributor Author

LuukvH commented Aug 26, 2024

@ddnexus I added it to this pr. See the rails.ru. I ran it, with and without the change.

@LuukvH
Copy link
Contributor Author

LuukvH commented Aug 28, 2024

@ddnexus Let me know if you require anything else.

LuukvH and others added 2 commits August 28, 2024 18:17
This commit updates the code to prefix certain class names with the Pagy module name. The change is necessary to prevent potential collisions with class names defined in Rails applications.

These adjustments ensure that the Pagy pagination library operates correctly without interfering with other classes that might exist within the application namespace. The revised code now properly isolates Pagy-specific classes, enhancing compatibility and stability

feat: Break it
@ddnexus
Copy link
Owner

ddnexus commented Aug 28, 2024

OK, so the problem is not that the pagy modules are "conflicting" with app defined classes. It's that when they are not defined... the generic ruby module resolution of the modules passed to the defined? method may find other modules not in the ::Pagy root namespace.

The 2d61ac7 commit absolutizes all the namespaces passed to the defined? method. That triggers the condition only for ::Pagy modules. Then the conditional statement get resolved by ruby even in abbreviated form, which is simpler to read and safe to use from inside the ::Pagy namespace.

Please, let me know if that solves all the possible cases.
Thank you

@LuukvH
Copy link
Contributor Author

LuukvH commented Aug 29, 2024

@ddnexus Seems a goog improvement to me to absolutize the modules.
I tested a set of use cases within our source code and this indeed solve the issue we were having.

@ddnexus ddnexus merged commit a3da3cd into ddnexus:master Aug 30, 2024
9 checks passed
@ddnexus
Copy link
Owner

ddnexus commented Aug 30, 2024

Thnk you!

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.

2 participants