<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: FROWNINGdev</title>
    <description>The latest articles on DEV Community by FROWNINGdev (@frowningdev).</description>
    <link>https://dev.to/frowningdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4145968%2Ff14506a0-72a1-4f9b-aaf7-79ad032089b9.jpg</url>
      <title>DEV Community: FROWNINGdev</title>
      <link>https://dev.to/frowningdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frowningdev"/>
    <language>en</language>
    <item>
      <title>24 open-source Django projects vs. my static parser: the Django code tutorials never show</title>
      <dc:creator>FROWNINGdev</dc:creator>
      <pubDate>Fri, 27 Nov 2026 12:37:44 +0000</pubDate>
      <link>https://dev.to/frowningdev/24-open-source-django-projects-vs-my-static-parser-the-django-code-tutorials-never-show-3pb0</link>
      <guid>https://dev.to/frowningdev/24-open-source-django-projects-vs-my-static-parser-the-django-code-tutorials-never-show-3pb0</guid>
      <description>&lt;p&gt;I maintain &lt;a href="https://github.com/FROWNINGdev/orm-lens" rel="noopener noreferrer"&gt;orm-lens&lt;/a&gt;, a static analyzer for Django models and migrations. It reads source files only: no database, no settings module, no &lt;code&gt;django.setup()&lt;/code&gt;. That makes it fast and lets it run on a half-broken checkout. It also means every model, field and migration has to be understood from the text alone.&lt;/p&gt;

&lt;p&gt;This month I ran it over 24 open-source Django codebases it had never seen: NetBox, PostHog, authentik, Plane, paperless-ngx, Healthchecks, saleor, wagtail, Label Studio, pretix, Weblate, Taiga, InvenTree, Kiwi TCMS, Mayan EDMS, Misago, CVAT, Ralph, Zulip, Read the Docs, Nautobot, Tandoor Recipes, wger and django-oscar. Then I read every place where its answer didn't match what Django would do.&lt;/p&gt;

&lt;p&gt;None of what follows is a bug in those projects. It is all valid Django and most of it is idiomatic. It just isn't the Django you see in the tutorial, where every model is &lt;code&gt;class Foo(models.Model)&lt;/code&gt; and every field is &lt;code&gt;models.Something(...)&lt;/code&gt;. If you write a linter, a codemod or a migration check for Django, this is the list I wish I'd had.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class headers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A call in the base list (Tandoor Recipes)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Recipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ExportModelOperationsMixin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"recipe"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PermissionModelMixin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/korfuri/django-prometheus" rel="noopener noreferrer"&gt;django-prometheus&lt;/a&gt; exports per-model metrics through a mixin &lt;em&gt;factory&lt;/em&gt;: &lt;code&gt;ExportModelOperationsMixin("recipe")&lt;/code&gt; returns a class, and Python accepts any expression in a base list. orm-lens found class headers with a regex that read the bases as "everything up to the first &lt;code&gt;)&lt;/code&gt;", which here is the end of &lt;code&gt;("recipe"&lt;/code&gt;. Tandoor lost 22 of its models this way, including &lt;code&gt;Recipe&lt;/code&gt;, &lt;code&gt;Step&lt;/code&gt; and &lt;code&gt;Ingredient&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The result of a call can't be resolved statically anyway, so the fix drops calls from the base list and lets the remaining bases decide whether the class is a model. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/335" rel="noopener noreferrer"&gt;#335&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  A base looked up by name (django-oscar)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;oscar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_model&lt;/span&gt;

&lt;span class="nc"&gt;Benefit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"offer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Benefit"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PercentageDiscountBenefit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Benefit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oscar lets every project override any model, so its own code never imports model classes. It asks the app registry for them by label and name. To a parser that follows imports, &lt;code&gt;Benefit&lt;/code&gt; is just a module-level variable, and all 12 benefit and condition proxies vanished. orm-lens now treats &lt;code&gt;X = get_model("app", "Model")&lt;/code&gt; as a binding to that model. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/341" rel="noopener noreferrer"&gt;#341&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Fields that come from somewhere you don't parse
&lt;/h3&gt;

&lt;p&gt;Read the Docs has 24 models on django-extensions' &lt;code&gt;TimeStampedModel&lt;/code&gt;. InvenTree, Mayan and Misago build trees on &lt;code&gt;MPTTModel&lt;/code&gt;. Kiwi TCMS uses django-tree-queries, Mayan uses django-solo. Each of these abstract bases brings fields (&lt;code&gt;created&lt;/code&gt;/&lt;code&gt;modified&lt;/code&gt;, &lt;code&gt;lft&lt;/code&gt;/&lt;code&gt;rght&lt;/code&gt;/&lt;code&gt;tree_id&lt;/code&gt;/&lt;code&gt;level&lt;/code&gt;, ...) that appear in every migration and in no &lt;code&gt;models.py&lt;/code&gt; of the project.&lt;/p&gt;

&lt;p&gt;A source-only tool doesn't read site-packages, so it has to know the popular bases by name. Without that, &lt;code&gt;drift&lt;/code&gt; reported 24 of Read the Docs' models as missing two columns each. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/336" rel="noopener noreferrer"&gt;#336&lt;/a&gt;, &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/302" rel="noopener noreferrer"&gt;#302&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  The field nobody declares (Ralph)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BaseObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;remarks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Asset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseObject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;hostname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With concrete inheritance Django adds a one-to-one link to the parent, &lt;code&gt;baseobject_ptr&lt;/code&gt;, and &lt;code&gt;makemigrations&lt;/code&gt; writes it into the child's &lt;code&gt;CreateModel&lt;/code&gt;. The model never declares it. Ralph is built on a concrete &lt;code&gt;BaseObject&lt;/code&gt;, and the link showed up as drift 25 times. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/301" rel="noopener noreferrer"&gt;#301&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Field declarations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Alphabetical keyword arguments (Mayan EDMS)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;related_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;verbose_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Document"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mayan writes every field with keyword arguments in alphabetical order, so &lt;code&gt;to=&lt;/code&gt; is never first. The parser stripped one closing parenthesis too many when the last argument was itself a call (&lt;code&gt;_("Document")&lt;/code&gt;), fell back to "take the first identifier", and read the target as &lt;code&gt;on_delete&lt;/code&gt;. That hit 81 of Mayan's 92 relations. The test suite had kwarg-order tests; none of them ended in a call. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/300" rel="noopener noreferrer"&gt;#300&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Fields imported by name (Taiga, Label Studio)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contrib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ArrayField&lt;/span&gt;

&lt;span class="n"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ArrayField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;models.Anything(...)&lt;/code&gt; is easy to spot. &lt;code&gt;ArrayField(...)&lt;/code&gt;, &lt;code&gt;HStoreField(...)&lt;/code&gt; and &lt;code&gt;GeneratedField(...)&lt;/code&gt; are almost always imported by name, and a bare call only counts as a field if the parser knows the name. 15 of Taiga's 18 drift entries were &lt;code&gt;ArrayField&lt;/code&gt;s. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/250" rel="noopener noreferrer"&gt;#250&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Migration names that don't start with four digits (pretix)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;0162b_auto_20201218_1810.py&lt;/code&gt;, &lt;code&gt;008_remove_scheduled_mails.py&lt;/code&gt;. Django doesn't care what a migration file is called: its loader imports every module in &lt;code&gt;migrations/&lt;/code&gt; that doesn't start with &lt;code&gt;_&lt;/code&gt; or &lt;code&gt;~&lt;/code&gt;. orm-lens only read files matching &lt;code&gt;^\d{4}_&lt;/code&gt;. The fields added in &lt;code&gt;0162b&lt;/code&gt; showed up as "declared but never migrated", and with &lt;code&gt;008&lt;/code&gt; gone, the migration before it looked like a second leaf, which is a critical "conflicting migrations" finding for a perfectly linear history. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/246" rel="noopener noreferrer"&gt;#246&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Python 3.14 syntax in a data migration (Read the Docs)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;SyntaxError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://peps.python.org/pep-0758/" rel="noopener noreferrer"&gt;PEP 758&lt;/a&gt; lets &lt;code&gt;except&lt;/code&gt; take several types without parentheses. Read the Docs already uses it in a data migration. On Python 3.13 and older &lt;code&gt;ast.parse()&lt;/code&gt; fails on that file, the migration was dropped silently, and the gap it left in the graph turned into a false "conflicting leaves". A tool that runs on the user's interpreter will meet source written for a newer one. Now a migration that won't parse marks its app's graph as unknown, and the leaf check stays silent instead of guessing. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/337" rel="noopener noreferrer"&gt;#337&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  The app label isn't the directory name (Misago)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# misago/threads/migrations/0002_threads_settings.py&lt;/span&gt;
&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"misago_threads"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"0001_initial"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every Misago app sets &lt;code&gt;AppConfig.label&lt;/code&gt;, and migration dependencies carry the label, not the folder name. &lt;code&gt;migration-deps threads&lt;/code&gt; matched on the folder, saw no in-app dependencies at all, and printed all 39 migrations as both roots and leaves. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/327" rel="noopener noreferrer"&gt;#327&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Signals
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;@receiver&lt;/code&gt; with a keyword (pretix)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@receiver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;post_save&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;on_order_saved&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Django docs pass the signal positionally. pretix passes it as &lt;code&gt;signal=&lt;/code&gt; in about 40 places, and each became an &lt;code&gt;&amp;lt;unknown&amp;gt;&lt;/code&gt; signal. (&lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/248" rel="noopener noreferrer"&gt;#248&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  What I take from it
&lt;/h2&gt;

&lt;p&gt;A static tool for Django has to model Django's &lt;em&gt;rules&lt;/em&gt;, not the shape of the code in the docs. The rule is "a base list is any expression", not "a base list is a few dotted names"; "a migration is any module in &lt;code&gt;migrations/&lt;/code&gt; with a &lt;code&gt;Migration&lt;/code&gt; class", not "a file called &lt;code&gt;NNNN_*.py&lt;/code&gt;". Each time I wrote the shape instead of the rule, some real project broke it.&lt;/p&gt;

&lt;p&gt;Synthetic tests didn't catch any of these. They check the cases I thought of. The only thing that finds the cases I didn't think of is code I didn't write, so every parser change is now run against a corpus of real projects before it merges, and the output is compared with main.&lt;/p&gt;

&lt;p&gt;Every item above became a GitHub issue with a minimal repro, the file to start in and the test that should pass. Since 9 November, 25 people have sent 58 merged pull requests, most of them on these issues, and most within hours of the issue going up. Two from this list are still open if you want one: &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/254" rel="noopener noreferrer"&gt;#254&lt;/a&gt; (field classes defined in the project itself) and &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues/308" rel="noopener noreferrer"&gt;#308&lt;/a&gt; (apps whose directories share a name).&lt;/p&gt;

&lt;p&gt;Try it on your own project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvx orm-lens list -v        &lt;span class="c"&gt;# every model it found&lt;/span&gt;
uvx orm-lens drift          &lt;span class="c"&gt;# models.py vs. the migration history&lt;/span&gt;
uvx orm-lens migration-risk &lt;span class="c"&gt;# migrations that break on a populated table&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it gets your project wrong, &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;. That's where this list came from.&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>opensource</category>
      <category>staticanalysis</category>
    </item>
    <item>
      <title>The best good first issues are your own tool's mistakes</title>
      <dc:creator>FROWNINGdev</dc:creator>
      <pubDate>Thu, 19 Nov 2026 05:52:26 +0000</pubDate>
      <link>https://dev.to/frowningdev/the-best-good-first-issues-are-your-own-tools-mistakes-4g9</link>
      <guid>https://dev.to/frowningdev/the-best-good-first-issues-are-your-own-tools-mistakes-4g9</guid>
      <description>&lt;p&gt;On Saturday, November 14, at 12:08 UTC I opened ten issues on &lt;a href="https://github.com/FROWNINGdev/orm-lens" rel="noopener noreferrer"&gt;orm-lens&lt;/a&gt;, a static analyzer for Django models and migrations. The first pull request arrived 29 minutes later. By 20:00 there were nine PRs from eight people, and seven of them were merged the same day.&lt;/p&gt;

&lt;p&gt;The week before, a batch of ten went the same way: six people, all ten closed in two days. Five days after the second batch the count stood at 22 external pull requests from 12 people, and when I opened the next batch this morning, the first PR came in 25 minutes.&lt;/p&gt;

&lt;p&gt;I didn't do anything clever with labels or bots. What changed is where the issues came from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the issues come from
&lt;/h2&gt;

&lt;p&gt;orm-lens reads Django source without importing Django, so it can be wrong in ways its own test suite never shows. The only way I know to find those is to run it on code it has never seen.&lt;/p&gt;

&lt;p&gt;For this batch I picked four large open-source Django projects: pretix, Weblate, Label Studio and Taiga. I ran every command on each one and read the output looking for answers that were wrong, not just ugly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;migrations named &lt;code&gt;0162b_...py&lt;/code&gt; were silently skipped, so the migration graph had holes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@receiver(signal=post_save, sender=Order)&lt;/code&gt; with the signal passed by keyword lost the signal name&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ArrayField&lt;/code&gt; imported by name (&lt;code&gt;from django.contrib.postgres.fields import ArrayField&lt;/code&gt;) dropped the field from the model&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;select_related("date_from")&lt;/code&gt; was suggested for a plain datetime attribute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of those is a small, self-contained bug with an obvious expected output. That's the whole trick.&lt;/p&gt;

&lt;h2&gt;
  
  
  What goes in the issue
&lt;/h2&gt;

&lt;p&gt;Every issue had the same five sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What happens.&lt;/strong&gt; One paragraph, with the real project and file where it showed up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repro.&lt;/strong&gt; A minimal &lt;code&gt;models.py&lt;/code&gt; (or migration) of 5–15 lines and the exact command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actual vs expected output.&lt;/strong&gt; Copied from the terminal, not described.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where.&lt;/strong&gt; The file and roughly which function to start in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to test.&lt;/strong&gt; Which test file to add to, and what the assertion should be.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Writing these takes longer than writing the fix would. That's fine. The point isn't to save my time on this bug; it's that someone new can go from "never seen this repo" to a green PR in an evening, and come back for the next one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd skip
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vague tickets.&lt;/strong&gt; "Improve the docs" or "add more tests" sat open for months in my repo. Nobody knows when they're done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tickets that need design decisions.&lt;/strong&gt; Two of the ten were bigger: a field declared under &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;else&lt;/code&gt; in the class body, and field classes defined in the project itself. I labelled those &lt;code&gt;help wanted&lt;/code&gt;, not &lt;code&gt;good first issue&lt;/code&gt;, and the one that got a PR needed a longer review.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Waiting to review.&lt;/strong&gt; CI on fork PRs needs a manual approval on GitHub. A PR that sits in &lt;code&gt;action_required&lt;/code&gt; for a day loses its author. I approve the run after reading the diff, and review the same day.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The review is part of the issue
&lt;/h2&gt;

&lt;p&gt;Not every PR was right the first time. One fixed the reported case but broke the opposite one: a field declared under a condition and then declared again unconditionally kept the conditional type. Another fixed the bug but more than doubled the run time on a large project. Both reviews came in the same format as the issues: a minimal repro of the problem and the output I expected.&lt;/p&gt;

&lt;p&gt;If the issue is precise, the review can be precise too, and a newcomer can act on it without a long back-and-forth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it on your own project
&lt;/h2&gt;

&lt;p&gt;If you maintain a linter, a parser, a code generator, anything that reads other people's code: pick three big open-source projects in your niche, run your tool on them, and file every wrong answer with a repro. You get a better tool and a queue of issues people actually want to pick up.&lt;/p&gt;

&lt;p&gt;And if you work with Django, the open ones are &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues?q=is%3Aopen+label%3A%22good+first+issue%22" rel="noopener noreferrer"&gt;here&lt;/a&gt;. To see what the tool does on your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvx orm-lens migration-risk   &lt;span class="c"&gt;# migrations that break on a populated table&lt;/span&gt;
uvx orm-lens nplusone         &lt;span class="c"&gt;# N+1 loops, with the select_related to add&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>opensource</category>
      <category>beginners</category>
      <category>python</category>
      <category>django</category>
    </item>
    <item>
      <title>Django 6.1's DB_CASCADE skips your post_delete handlers</title>
      <dc:creator>FROWNINGdev</dc:creator>
      <pubDate>Tue, 10 Nov 2026 05:43:15 +0000</pubDate>
      <link>https://dev.to/frowningdev/django-61s-dbcascade-skips-your-postdelete-handlers-m58</link>
      <guid>https://dev.to/frowningdev/django-61s-dbcascade-skips-your-postdelete-handlers-m58</guid>
      <description>&lt;p&gt;Django 6.1 added three &lt;code&gt;on_delete&lt;/code&gt; policies that run in the database instead of in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Attachment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"shop.Order"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DB_CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FileField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;DB_CASCADE&lt;/code&gt;, &lt;code&gt;DB_SET_NULL&lt;/code&gt; and &lt;code&gt;DB_SET_DEFAULT&lt;/code&gt; put &lt;code&gt;ON DELETE CASCADE&lt;/code&gt; / &lt;code&gt;SET NULL&lt;/code&gt; / &lt;code&gt;SET DEFAULT&lt;/code&gt; on the foreign-key constraint and let the database do the work. Deleting an &lt;code&gt;Order&lt;/code&gt; becomes one &lt;code&gt;DELETE&lt;/code&gt; statement. Django no longer loads every child row into memory first to find out what else it has to delete.&lt;/p&gt;

&lt;p&gt;That speed has a cost, and the 6.1 release notes say so: &lt;strong&gt;&lt;code&gt;DB_CASCADE&lt;/code&gt; does not send &lt;code&gt;pre_delete&lt;/code&gt; or &lt;code&gt;post_delete&lt;/code&gt; for the rows the database removes.&lt;/strong&gt; Django never sees those rows, so it has nothing to send signals about.&lt;/p&gt;

&lt;h2&gt;
  
  
  What stops working
&lt;/h2&gt;

&lt;p&gt;Most projects have at least one delete handler they no longer think about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signals&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;post_delete&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dispatch&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;receiver&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Attachment&lt;/span&gt;

&lt;span class="nd"&gt;@receiver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post_delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Attachment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;delete_file_from_storage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the ORM's &lt;code&gt;CASCADE&lt;/code&gt;, deleting an order deletes its attachments &lt;em&gt;and&lt;/em&gt; calls this handler once per attachment, so the files leave S3 too. Switch the foreign key to &lt;code&gt;DB_CASCADE&lt;/code&gt; and the rows still disappear, but the handler never runs. You get no error and no log line, and the files stay in the bucket.&lt;/p&gt;

&lt;p&gt;The same goes for audit trails written on delete, search-index removal, cache invalidation, and counters kept in sync by signals. A receiver registered with no &lt;code&gt;sender&lt;/code&gt; ("log every delete") is also skipped for those rows.&lt;/p&gt;

&lt;p&gt;Third-party apps count too. django-cleanup and django-simple-history both listen to &lt;code&gt;post_delete&lt;/code&gt;. If they cover a model you move to &lt;code&gt;DB_CASCADE&lt;/code&gt;, assume they stop covering the rows the database deletes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding them before you switch
&lt;/h2&gt;

&lt;p&gt;Grepping for &lt;code&gt;post_delete&lt;/code&gt; gets you the handlers, but not which ones a given &lt;code&gt;DB_CASCADE&lt;/code&gt; foreign key will silence. You also have to match each receiver's &lt;code&gt;sender&lt;/code&gt; against the models on the receiving end of the cascade, and remember that a sender-less receiver matches all of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/FROWNINGdev/orm-lens" rel="noopener noreferrer"&gt;orm-lens&lt;/a&gt; does that matching statically: it reads your source, so it needs no database and no &lt;code&gt;django.setup()&lt;/code&gt;. Since py-1.13.8, &lt;code&gt;cascade&lt;/code&gt; lists the delete handlers each &lt;code&gt;DB_CASCADE&lt;/code&gt; relation skips:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ uvx orm-lens cascade shop.Order
deleting one shop.Order row:
  CASCADE-deletes rows in (1):
    - shop.Attachment  via order (db)
  (db) = on_delete=DB_*: the database applies it, so Django sends no delete signals for those rows.
  ! 1 delete receiver(s) will NOT run for (db) rows:
    - post_delete shop.signals.delete_file_from_storage  for shop.Attachment  (shop/signals.py:6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--format json&lt;/code&gt; puts the same list under &lt;code&gt;skipped_receivers&lt;/code&gt;, so a CI step can fail on it. The MCP server's &lt;code&gt;cascade_preview&lt;/code&gt; tool returns it too, so an AI agent that proposes switching to &lt;code&gt;DB_CASCADE&lt;/code&gt; gets told which handlers go quiet.&lt;/p&gt;

&lt;p&gt;What the scan does not cover, so you know where to look by hand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It reads &lt;code&gt;@receiver(...)&lt;/code&gt; decorators and &lt;code&gt;post_delete.connect(handler, sender=Model)&lt;/code&gt; calls in your project.&lt;/li&gt;
&lt;li&gt;Receivers that third-party packages register inside site-packages are not scanned.&lt;/li&gt;
&lt;li&gt;It reports one level of cascade. Run it again for each model it lists, the same way the database will follow the constraints.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do with a handler that would be skipped
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep the ORM's &lt;code&gt;CASCADE&lt;/code&gt; on that relation.&lt;/strong&gt; &lt;code&gt;DB_CASCADE&lt;/code&gt; is opt-in per foreign key. Use it where deletes are hot and side-effect free, and keep &lt;code&gt;CASCADE&lt;/code&gt; where a handler has to run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do the side effect explicitly.&lt;/strong&gt; Collect the file names before you delete the parent, then remove them after the transaction commits (&lt;code&gt;transaction.on_commit&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make it durable if losing one matters.&lt;/strong&gt; An &lt;code&gt;on_commit&lt;/code&gt; callback runs in the same process, so a crash right after the commit loses it and the files stay. Write the file names to a cleanup table in the same transaction as the delete (an outbox), and let a worker remove each object and mark its row done. The worker can retry safely, because deleting an object that is already gone changes nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check for shared files first.&lt;/strong&gt; If two rows can point at the same storage object (copied records, deduplicated uploads), delete the object only when no remaining row references it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean up asynchronously.&lt;/strong&gt; A periodic job that deletes storage objects with no matching row is slower to converge, but it survives any delete path, raw SQL included.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What you should not do is switch the policy and trust that the handlers still fire. The rows disappear either way, so nothing tells you the handler stopped running.&lt;/p&gt;




&lt;p&gt;orm-lens is free and MIT: a VS Code extension, a CLI (&lt;code&gt;pip install orm-lens&lt;/code&gt;) and an MCP server for AI agents, all working from your source. It also handles the older ways of writing a cascade. A positional &lt;code&gt;ForeignKey(Order, models.CASCADE)&lt;/code&gt;, the way &lt;code&gt;django.contrib&lt;/code&gt; writes it, and &lt;code&gt;DO_NOTHING&lt;/code&gt;, which leaves rows for the constraint to reject, are both reported since py-1.13.7.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Updated 10 November 2026 with the outbox and shared-file points from the comments below. Originally published on the &lt;a href="https://frowningdev.github.io/orm-lens/docs/articles/django-6-1-db-cascade-signals.html" rel="noopener noreferrer"&gt;orm-lens site&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>postgres</category>
      <category>opensource</category>
    </item>
    <item>
      <title>My Django migration linter raised 407 alarms on six big codebases. 405 were wrong</title>
      <dc:creator>FROWNINGdev</dc:creator>
      <pubDate>Tue, 10 Nov 2026 05:11:02 +0000</pubDate>
      <link>https://dev.to/frowningdev/my-django-migration-linter-raised-407-alarms-on-six-big-codebases-405-were-wrong-29ka</link>
      <guid>https://dev.to/frowningdev/my-django-migration-linter-raised-407-alarms-on-six-big-codebases-405-were-wrong-29ka</guid>
      <description>&lt;p&gt;I maintain &lt;a href="https://github.com/FROWNINGdev/orm-lens" rel="noopener noreferrer"&gt;orm-lens&lt;/a&gt; (until recently django-orm-lens), a static analyzer for Django models and migrations. One of its checks, &lt;code&gt;migration-risk&lt;/code&gt;, reads every migration file and flags operations that break on a table that already has rows: a &lt;code&gt;NOT NULL&lt;/code&gt; column with no default, a &lt;code&gt;UNIQUE&lt;/code&gt; column that existing duplicates will violate, an index build that locks the table.&lt;/p&gt;

&lt;p&gt;Its test suite was green, so I pointed it at real projects:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Project&lt;/th&gt;
&lt;th&gt;GitHub stars&lt;/th&gt;
&lt;th&gt;Critical findings&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;NetBox&lt;/td&gt;
&lt;td&gt;21.8k&lt;/td&gt;
&lt;td&gt;212&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PostHog&lt;/td&gt;
&lt;td&gt;40.5k&lt;/td&gt;
&lt;td&gt;79&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;authentik&lt;/td&gt;
&lt;td&gt;26.2k&lt;/td&gt;
&lt;td&gt;58&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Healthchecks&lt;/td&gt;
&lt;td&gt;10.5k&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Plane&lt;/td&gt;
&lt;td&gt;61.7k&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;paperless-ngx&lt;/td&gt;
&lt;td&gt;47.4k&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is &lt;strong&gt;407 critical findings&lt;/strong&gt;. I read every one, and two were real.&lt;/p&gt;

&lt;p&gt;The other 405 were not edge cases. Each came from something Django does when it migrates a populated table, which I had modelled wrongly. Here they are, ordered by how many false alarms each caused.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Squashed migrations never touch a populated table (208)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;replaces&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dcim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"0002_auto_..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dcim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"0059_..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A squashed migration only runs on a fresh database. On a database where the replaced migrations are already applied, Django marks the squash as applied without running it. On a database where only some of them are applied, it keeps running the originals. Either way, every &lt;code&gt;AddField&lt;/code&gt; inside a squash lands on an empty table. Squashes alone made up more than half of all the alarms.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;blank=True&lt;/code&gt; text fields get &lt;code&gt;""&lt;/code&gt; (83)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"virtualmachine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"serial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No &lt;code&gt;default=&lt;/code&gt; and no &lt;code&gt;null=True&lt;/code&gt;, so the column is &lt;code&gt;NOT NULL&lt;/code&gt;, yet this is safe. &lt;code&gt;BaseDatabaseSchemaEditor._effective_default()&lt;/code&gt; fills existing rows with &lt;code&gt;""&lt;/code&gt; for any &lt;code&gt;blank=True&lt;/code&gt; field whose class allows empty strings. Projects also subclass &lt;code&gt;CharField&lt;/code&gt;: NetBox's &lt;code&gt;ColorField(blank=True, max_length=6)&lt;/code&gt; gets the same treatment. The linter now treats a &lt;code&gt;max_length&lt;/code&gt; argument as a sign of a text field.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Many-to-many fields add no column (37)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ManyToManyField&lt;/code&gt;, django-taggit's &lt;code&gt;TaggableManager&lt;/code&gt; and &lt;code&gt;GenericRelation&lt;/code&gt; create a join table, or nothing at all. They are never a &lt;code&gt;NOT NULL&lt;/code&gt; risk on the model's own table.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;code&gt;makemigrations&lt;/code&gt; splits foreign keys out of &lt;code&gt;CreateModel&lt;/code&gt; (25)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ContactGroupMembership"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"contactgroupmembership"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To break dependency cycles, the autodetector creates the table first and adds some foreign keys afterwards, in the same migration. That table was created a few lines earlier, so it is empty.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A squash and the migrations it replaces are not two leaves (17)
&lt;/h2&gt;

&lt;p&gt;Django refuses to migrate an app whose migration graph has two leaf nodes. The check flagged authentik's apps as conflicting because the squash and the last migration it replaces both looked like leaves. The loader drops the replaced nodes and points their dependents at the squash, so the linter now does the same before it counts leaves.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;code&gt;auto_now&lt;/code&gt;, &lt;code&gt;db_default&lt;/code&gt; and &lt;code&gt;GeneratedField&lt;/code&gt; fill themselves (16)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;auto_now_add=True&lt;/code&gt; gets the current time on &lt;code&gt;ADD COLUMN&lt;/code&gt;, and &lt;code&gt;db_default&lt;/code&gt; is a database-side default. A &lt;code&gt;GeneratedField&lt;/code&gt; is computed by the database. None of them needs &lt;code&gt;default=&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. NULLs don't collide (12)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Existing rows get &lt;code&gt;NULL&lt;/code&gt;. On PostgreSQL, MySQL and SQLite a unique constraint never treats two NULLs as equal, so this is safe. The same holds for &lt;code&gt;default=None&lt;/code&gt;, which authentik uses on four fields across three migrations.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Names that come back (5)
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;RemoveField&lt;/code&gt; followed by an &lt;code&gt;AddField&lt;/code&gt; of the same name, or a &lt;code&gt;RenameField&lt;/code&gt; onto it, leaves the field in place. So does a &lt;code&gt;DeleteModel&lt;/code&gt; followed by a &lt;code&gt;CreateModel&lt;/code&gt;. The linter compared each historical removal with today's &lt;code&gt;models.py&lt;/code&gt;, saw the field still there, and called it drift.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Data migrations that run first (2)
&lt;/h2&gt;

&lt;p&gt;authentik adds a &lt;code&gt;NOT NULL&lt;/code&gt; column right after a &lt;code&gt;RunPython&lt;/code&gt; that, its comment says, deletes every row. A static tool cannot prove what a &lt;code&gt;RunPython&lt;/code&gt; does, so this is now a warning that says why, rather than a certain critical.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two that were real
&lt;/h2&gt;

&lt;p&gt;PostHog's &lt;code&gt;0308_add_indirect_person_override_constraints&lt;/code&gt; removes two foreign-key columns and adds them back as &lt;code&gt;NOT NULL&lt;/code&gt; with no default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RemoveField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"personoverride"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"old_person_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"personoverride"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"old_person_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a populated &lt;code&gt;personoverride&lt;/code&gt; table this fails. The table may well have been empty when it shipped. The linter cannot know that, and it does not pretend to.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same exercise for N+1
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;nplusone&lt;/code&gt; had its own share of noise: writes through a relation (&lt;code&gt;interface.vdcs.set(...)&lt;/code&gt;) reported as reads, one field suggested in both &lt;code&gt;select_related&lt;/code&gt; and &lt;code&gt;prefetch_related&lt;/code&gt;, and loops in test files. After those fixes I drew a random sample of the remaining high-confidence findings across the six projects, and all six were real N+1s. One example is &lt;code&gt;installation.organization&lt;/code&gt; read inside a loop over installations, which is fixed with &lt;code&gt;select_related("organization")&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;p&gt;A static analyzer is only as good as its precision on code it has never seen. Synthetic test fixtures confirmed that the rules did what I wrote. They could not tell me whether what I wrote was true of Django. Big open-source codebases can, and running against them is now part of how the rules are tested. Each of the nine causes above is now its own test case, so a later refactor that forgets how Django migrates a populated table fails the suite instead of shipping.&lt;/p&gt;

&lt;p&gt;The other rule is the one from cause 9: severity follows certainty. When the linter cannot prove a risk, because a &lt;code&gt;RunPython&lt;/code&gt; it cannot see through runs first, it says "warning, and here is why I can't be sure" instead of "critical". A check that is wrong 405 times out of 407 teaches people to skim the whole report, and then the two real findings get skimmed too.&lt;/p&gt;

&lt;p&gt;All of the above shipped in py-1.14.0. Try it on your own history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvx orm-lens migration-risk      &lt;span class="c"&gt;# migration findings, critical by default&lt;/span&gt;
uvx orm-lens nplusone            &lt;span class="c"&gt;# N+1 loops, with the select_related to add&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reads source only: no database, no settings module, no &lt;code&gt;django.setup()&lt;/code&gt;. It is free and MIT. If it is wrong about your project, &lt;a href="https://github.com/FROWNINGdev/orm-lens/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;. That is how this whole list came about.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Updated 10 November 2026 after a comment below. Originally published on the &lt;a href="https://frowningdev.github.io/orm-lens/docs/articles/407-migration-alarms.html" rel="noopener noreferrer"&gt;orm-lens site&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>postgres</category>
      <category>opensource</category>
    </item>
    <item>
      <title>I built a Django linter that never imports Django</title>
      <dc:creator>FROWNINGdev</dc:creator>
      <pubDate>Sun, 27 Sep 2026 20:07:59 +0000</pubDate>
      <link>https://dev.to/frowningdev/i-built-a-django-linter-that-never-imports-django-4oip</link>
      <guid>https://dev.to/frowningdev/i-built-a-django-linter-that-never-imports-django-4oip</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0brmayo3rlafvakgbrjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0brmayo3rlafvakgbrjq.png" alt=" " width="800" height="336"&gt;&lt;/a&gt;&lt;br&gt;
Some background on why static: the drift check was the feature that convinced me. Django's own makemigrations --check is the right answer, but it needs every dependency installed and settings that import cleanly, so on a cold CI runner or a broken venv it simply can't run. Replaying migration files into a field set and diffing against models.py turned out to be enough to catch the dangerous direction (declared but never migrated) without any of that.&lt;/p&gt;

&lt;p&gt;It's also fast: the model graphs of Zulip, Saleor, Wagtail, django CMS and Mezzanine parse together in about 20 ms on a laptop.&lt;/p&gt;

</description>
      <category>codequality</category>
      <category>django</category>
      <category>performance</category>
      <category>python</category>
    </item>
  </channel>
</rss>
