502 Bad Gateway from ActiveRecord->validate()

I’m getting a 502 bad gateway error when trying to create a record. Updating records works fine but I’ve traced this error to the


call in my model.

bad gateway indicates that either php-fpm crashed (in which case every request on every site on the host will show this error), or that you’re causing an error in this script so heinous that the PHP thread crashes before it can report an error. it’s also possible that you’re rubbing an unstable extension the wrong way

to debug this sort of issue, first check the php log for the site and then the global php log for the host. If nothing there gives you a clue it’s time to play jezzball – comment out paths in you code into you isolate exactly what line, expression, or parameter is causing it

Debugged it down to attempting to create and save a one to many relationship before the original record was created. Ie I was attempting to create a question and its answers in which had 4 answers when the question was being created.

When I associated the answers with the questions it was failing because the question had not yet been created and thus had no ID to tag the item with.

The fix was to add the association to onRecordSaved and save the new answers records before creating the association.