Posts Tagged ‘bug’

Django auto_now types wreck get_or_create functionality

Tuesday, February 11th, 2014

I recently had occasion to lazily use the Django “get_or_create” convenience method to instantiate some database ORM records. This worked fine the first time through, and I didn’t have to write the tedious “query, check, then insert” rigamarole. So far so good. These were new records so the “or_create” part was operative.

Then, while actually testing the “get_” part by running over the same input dataset, I noticed it was nearly as slow as the INSERTs, even though it should have been doing indexed SELECTs over a modest, in-memory table. Odd. I checked the debug output from Django and discovered that get_or_create was invoking UPDATE calls.

The only field it was updating was:

updated_at = models.DateTimeField(auto_now=True)

Thanks, Django. You just created a tautological truth. It was updated at that datetime because … you updated it at that datetime.

Interestingly, its sister field did NOT get updated:

created_at = models.DateTimeField(auto_now_add=True, editable=False)

This field, true to its args, was not editable, even by whatever evil gnome was going around editing the updated_at field.

Recommendation: if you want actual timestamps in your database, why don’t you use a real database and put a trigger on it? ORM-layer nonsense is a surefire way to have everything FUBAR as soon as someone drops to raw SQL for performance or clarity.

iTunes “Sound Enhancer” Considered Harmful

Monday, October 18th, 2010

I have now on two occasions, with two separate, quiet background, vocal-heavy songs, noticed significant and highly distracting audio artifacts introduced by the default “Sound Enhancer” on iTunes for Mac (specifically, iTunes 9.2.1 (5) on Mac OS X 10.6.4, on a Quad-Core Mac Pro with an embarrassingly large amount of RAM).  The two songs were “You make me feel so young” sung by Frank Sinatra (from “Songs for Swingin’ Lovers”) and “Do I love you?” sung by Peggy Lee (from “Beauty and the Beat!”).

Both of these problems occurred with CD-ripped highish-bitrate audio tracks (MP3 at 160kbps and AAC at 256kbps/VBR, respsectively).  I originally thought the problem was that iTunes was using a faulty MP3 decoder until I determined that the problem was for AAC as well.  What finally sealed it was using QuickTime Player to listen to the same file and discovering the noise artifact had disappeared.

Compare these two, which I digitally captured using Audio Hijack (trial version; buy it if you like it!):

Version with iTunes “Sound Enhancer” enabled: http://rlucas.net/audio/do_i_love_you-itunes-sound-enhancer.aiff

Version played through Quicktime (no “Enhancer”): http://rlucas.net/audio/do_i_love_you-quicktime.aiff

(P.S., rightsholders don’t even think about flexing your DMCA at me.  These are 20-second audio quality demonstrations for nonprofit, educational and research purposes, and have no negative impact on market value of the works.  You are on notice that any DMCA abuses will be met with bad-faith treble-damage vengeance.)

Notice, on the second “Do I?” that the iTunes version has a big burst of static on the “I,” while the Quicktime version does not.  The artifact on “..so young” is similar, on the “You and I” at 1:57, but I don’t have the time to capture and post that as well.

The morals of this story:

  • TURN OFF “Sound Enhancer” in preferences.  Just do it.  Not worth it.
  • Upgrade your headphones.  Never noticed this until I moved up to some better hardware.  It gets lost in the Apple earbuds.
  • Don’t trust that because a device/program/product has a big following that it does the right thing, at least from a quality perspective.  (Yes, I know, this should be self-evident to anyone who’s been awake since, say, the Industrial Revolution, or since the invention of mass brewing, but give me a break; I’ve been in the grips of Apple fanboydom since 2003 or so.)
  • Trust your ears, debug your equipment, and don’t put up with shit.  I didn’t believe for a good long time that the problem existed at all, much less that it could have been upstream from my headphones, until I debugged it.  Digital audio holds a promise for mankind, damn it, and you’ve got to make it live up to its potential.