osTicket/osTicket-1.8 — pull request #1012 by greezybacon (2014-06-10 21:30:01+00:00)
Title: orm: Fix issues surrounding MySQL commands OoS

Several places in the code initialize a list of objects from the database and only fetch one item. In certain instances (which seem almost like a race condition), MySQL will feel like there are more records available in the database and will complain with "Commands out of sync, you can't run the command now".

This patch addresses the issue by utilizing the ::one() method of the QuerySet where only one record is expected. The ::one() method is further designed to fetch all one results (which satisfies the MySQL client library) and return the first item.