Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I am trying to create a page (using db_persist) and then edit that same page (again using db_persist) in the same script. I believe I am running into issues because of a related page I have setup.

The basic flow is like this.

Code: Select all
<db_persist _mode='create' related_page=related_page_id>
<cms:set tran_id=k_last_inserted_id 'global' />
</cms:db_persist>

<cms:external_api_call invoice=tran_id /> //Sets api_tran_date variable

<cms:db_persist _mode='edit' _page_id=tran_id tran_date=api_tran_date>
//Some code here to handle errors and such
</cms:db_persist>


When I make the db_persist edit call I get the error "Duplicate entry 'XXX' for key 'PRIMARY'". I tried adding a php sleep call after the initial db_persist create call, to give the database time to catch up, but it didn't seem to help.

Additionally, when this happens, the record created by the first db_persist call seems to disappear. I know it existed, even if only temporarily, because the API I am passing it to records it.

I'm suspecting SQL transaction based issues, but don't know the Couch database code well enough to be sure.

Any help would be greatly appreciated.

Stephen
Hi, at first there is an error here: k_last_inserted_id, it must be k_last_insert_id.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Secondly, there is a missing _masterpage parameter. Couch halts without it, so I have a reasonable doubt your posted code ever runs like you said. There would be no db queries. You seem then to be not telling the whole story.

And "Duplicate entry 'XXX' for key 'PRIMARY" can possibly point at failed installation. Try to reinstall latest Couch2 from github (with a fresh new db of course) and 99% there would be no problem like that with correct db_persist code.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
3 posts Page 1 of 1
cron