AlchemyCMS / alchemy_cms

Alchemy is the Open Source Rails CMS framework for the component based web that can be used as classic server side rendered or headless CMS.
https://www.alchemy-cms.com
BSD 3-Clause "New" or "Revised" License
846 stars 314 forks source link

Elements for wrong page version searched #2816

Closed Olli closed 8 months ago

Olli commented 8 months ago

Steps to reproduce

Create a new page and add an element, save and publish everything. The page isn't shown public

Expected behavior

Elements get loaded and shown public

Actual behavior

Nothing is shown

System configuration

I think I've tracked down the problem. On creating a page there is also a page_version been created. After publishing the page a new version is created. The elements in the page unfortunately referencing to the first page_version but not to the published one.

tvdeyen commented 8 months ago

Have you verified that your timezone is set correctly? If not the published date might be UTC and if you are located somewhere else the page might not be public yet

Olli commented 8 months ago

Good point but no ... it's not a matter of timezones I think :)

Here are 2 datasets of alchemy_page_versions:

| 17 |       9 | NULL                | NULL         | 2024-04-03 16:17:18.967274 | 2024-04-03 16:17:18.967274 |
| 18 |       9 | 2024-03-01 17:18:00 | NULL         | 2024-04-03 16:18:33.981597 | 2024-04-04 06:56:40.510172 |

And that from the alchemy_elements:

| 23 | article_elements |        1 |      1 |      0 |      0 | 2024-04-03 16:17:18.998813 | 2024-04-03 16:17:19.517405 |       NULL |       NULL |              NULL |     0 |              17 |

You see ... it refers to page_version_id 17 instead of 18

tvdeyen commented 8 months ago

elements get copied from one page version to another during publish. not sure what the actual issue is you are describing here. can you provide an example application and show where the actual problem is?

what are you trying to do?

tvdeyen commented 8 months ago

what are article_elements? a custom table?

Olli commented 8 months ago

I only created a page, added an element (article_elements) to the page with some example content and published the page (and off course deleted the cache). But there is no output where it supposed to be. render_elements doesn't show anything so I started investigating and came across this SQL query which link the element to a page version (id 17) which isn't published.

At the end the workflow isn't complicated so that I can mess up something very easy ... this isn't the first CMS I use ;-) . The conclusion is, that this should be a bug. Tbh I'm not fully sure how the code works yet.

article_elements is a element consisting of a headline, an image and a text.

tvdeyen commented 8 months ago

Please make sure to join elements over the public_version_id from the alchemy_pages table.

But you can just use the elements or all_elements relation from a page to get the public elements.

again. but sure what you are trying to accomplish.

since we deployed dozens of production sites that do not have issues in that regard I do not see this as an Alchemy issue.

Converting to conversation instead.

Olli commented 8 months ago

I traced down the querys from the development.log and tried the SQL queries in the dbconsole. I'm fully aware that it works on many installations. I just want to put out a page ... nothing more nothing less. The right templates have been used but at render_elements no content is rendered and I'm wondering why because I obviously did everything right. The only issue for me is the reference to the wrong page version. To me this is an issue because if I replicate the SQL queries in the dbconsole no elements are fetched from the database so I assume this is the problem.

tvdeyen commented 8 months ago

Can this issue you are describing replicated with a freshly installed Alchemy? Or is it an issue with your local install? In another issue you were describing that you installed alchemy into an existing Rails app that used a different CMS before. Maybe during the install something went off?

Something you could check for is background processing. The publish page job is an active job. Do you have background processing set up? usually in development mode active job is set to run in process, but asynchronous.

just guessing here.

and again. this is more a discussion for the public boards or slack, but not an issue/bug until proven on a fresh install.

we also have a wast test suite ;)

you could also provide a failing test case as well.

Olli commented 8 months ago

I've investigated this a bit more. It worked with a fresh installed rails + alchemy. But I'm not sure what's different because. The different former CMS has been completely erased from the system.

Thx for your comments. I'll investigate it further. Unfortunately I have no slack account and don't want to have one ... I have Github. :-) I'll close this issue and add a comment if find something substantial.