• 
      

    Support comparing SQL when order is not guaranteed in some statements.

    Review Request #12040 — Created Feb. 5, 2022 and submitted — Latest diff uploaded

    Information

    Django Evolution
    release-2.x

    Reviewers

    Django doesn't always generate SQL statements in a pre-defined order.
    When adding or dropping multiple indexes, for example, it builds up
    indexes as a set, and then iterates through them. This made
    comparisons pretty unreliable.

    We now pass the generated and expected SQL through a normalization
    process. Sections of the expected SQL can be wrapped in a set, which
    will then be sorted. The matching section of the generated SQL will be
    sorted as well.

    This is not perfect. If the generated SQL in that range is not a match,
    it will still be sorted, and this can lead to some wonky results during
    comparison. The "Generated SQL" output still uses the original generated
    content, though, to help.

    This also will not work quite right if Django ends up generating any
    unordered SQL where each unordered item is actually a list of SQL
    statements, but currently it doesn't appear that that's something that
    happens. (Work was done to try to handle this case preemptively, but
    it's far too complicated.)

    Relevant series of statements has been updated to use this.

    Unit tests pass for all supported versions of Python and Django.

    Commits

    Files