The Daily WTF
Follow
Representative Line: Sort This Out
An anonymous submitter is working to fix issues left by a previous consultant. They began by addressing the most critical tickets. After clearing those, they started examining code that wasn't currently problematic but showed potential for future issues. While reviewing JavaScript, they discovered a custom sort function which raised immediate concerns. The first line of this function, obj[x._id.account_id] = x.count_total, was particularly alarming. The code incorrectly accesses an account_id field on what should be a MongoDB unique identifier. This indicates that an arbitrary object is being used as a unique identifier in the database, a practice deemed problematic. Beyond the identifier issue, the purpose of this code within a sorting function is unclear. The line appears to be building an object like {"id0": 5} rather than performing a sort. This situation presents a significant mystery, as the code has not yet caused a failure. The primary questions are why it hasn't broken and what will happen when it eventually does.