Why I Hate the Django ORM

Why I Hate the Django ORM

Edcdfd5affb524e0f88ec1a00ed3fe5d?s=128

Alex Gaynor

January 12, 2012
Tweet

Transcript

  1. WHY I HATE THE DJANGO ORM Thursday, January 12, 2012

  2. HI, I’M ALEX I HATE THE DJANGO ORM Thursday, January

    12, 2012
  3. I ALSO HELP BUILD IT (SO ALL OF THIS STUFF

    IS REALLY MY FAULT) Thursday, January 12, 2012
  4. WHY DO I HATE IT? Thursday, January 12, 2012

  5. SELECT event_type SUM(end_time - start_time) FROM event GROUP BY event_type

    Thursday, January 12, 2012
  6. TAKING A STEP BACK Thursday, January 12, 2012

  7. WHY DO WE HAVE AN ORM? DATABASE RECORDS INTO OBJECTS

    EXECUTE COMMON QUERIES NOT REPLACE SQL Thursday, January 12, 2012
  8. WAS THAT A COMMON QUERY? Thursday, January 12, 2012

  9. IT HAS A SYNTAX Event.objects.values( “event_type” ).annotate( Sum(F(“end_time”) - F(“start_time”))

    ) Thursday, January 12, 2012
  10. Traceback (most recent call last): File "<input>", line 1, in

    <module> File ".../query.py", line 741, in annotate is_summary=False) File ".../sql/query.py", line 990, in add_aggregate field_list = aggregate.lookup.split(LOOKUP_SEP) AttributeError: 'ExpressionNode' object has no attribute 'split' FFFFFFFUUUUUUUUUUUU Thursday, January 12, 2012
  11. AGGREGATES TAKE STRINGS (NOT EXPRESSIONS OR ANYTHING ELSE USEFUL) Thursday,

    January 12, 2012
  12. NO COMPOSABILITY Thursday, January 12, 2012

  13. WEREN’T DESIGNED WITH EACH OTHER IN MIND MUCH LESS A

    COMPREHENSIVE SYSTEM Thursday, January 12, 2012
  14. SQLALCHEMY session.query( TimlineEvent.event_type, func.sum(TimelineEvent.end_time - TimelineEvent.start_time) ).group_by( TimelineEvent.event_type ).all() Thursday,

    January 12, 2012
  15. NOTICE THAT? SQLALCHEMY USES THE SAME SYNTAX FOR FIELDS, EVERYWHERE

    Thursday, January 12, 2012
  16. DJANGO DOESN’T F(“field_name”) Aggregate(“field_name”) Q(field_name=value) filter(field_name=value) Thursday, January 12, 2012

  17. STRINGS, KEYWORD ARGUMENTS, AND FUNKY ONE-LETTER OBJECTS (WITH VARYING LEVELS

    OF INTEROPERABILITY) Thursday, January 12, 2012
  18. WHEN DO YOU USE WHICH? I HAVE NO IDEA (AND

    I WROTE THE DAMNED THING) Thursday, January 12, 2012
  19. SIMPLE THINGS ARE SIMPLE MEDIUM THINGS ARE POSSIBLE HARD THINGS

    AREN’T Thursday, January 12, 2012
  20. SIMPLE THINGS SHOULD BE SIMPLE HARD THINGS SHOULD BE POSSIBLE

    Thursday, January 12, 2012
  21. SPEAKING OF SIMPLE... Event.objects.filter( start_date__hour=10 ) Thursday, January 12, 2012

  22. AND OUGHT TO BE SIMPLE Event.objects.filter( start_date__hour__gt=11 ) Thursday, January

    12, 2012
  23. __ SYNTAX IS NEAT BUT LIMITED Thursday, January 12, 2012

  24. THE IDEALS OF THE ORM ARE GOOD THE API IS

    GREAT FOR SIMPLE CASES Thursday, January 12, 2012
  25. BUT THE INCONSISTENCIES BLEED AND THINGS THAT SHOULD BE EASY

    AREN’T Thursday, January 12, 2012
  26. 80/20 SOLUTION BUT IT COULD BE 90/10 Thursday, January 12,

    2012
  27. THANKS QUESTIONS? Thursday, January 12, 2012