Pull requests

#23 Merged

Fix sorted of None values in compare for python 3

  1. paradoxxxzero

Fix sorted of None values in compare for python 3

  • Learn about pull requests

Comments (5)

  1. paradoxxxzero author

    When using include_schemas=True in python3 with at least postgres, the autogenerate option does not work because the default schema is set to None and the table list is then sorted on it:

      File "alembic/env.py", line 152, in <module>                                                                                                                                                         
      File "alembic/env.py", line 132, in run_migrations_online                                                                                                                                            
      File "<string>", line 7, in run_migrations                                                                                                                                                           
      File "alembic/alembic/environment.py", line 689, in run_migrations                                                                                                                 
      File "alembic/alembic/migration.py", line 247, in run_migrations                                                                                                                   
      File "alembic/alembic/command.py", line 83, in retrieve_migrations                                                                                                                 
        autogen._produce_migration_diffs(context, template_args, imports)                                                                                                                                  
      File "alembic/alembic/autogenerate/api.py", line 137, in _produce_migration_diffs                                                                                                  
        autogen_context, object_filters, include_schemas)                                                                                                                                                  
      File "alembic/alembic/autogenerate/api.py", line 213, in _produce_net_changes                                                                                                      
        inspector, metadata, diffs, autogen_context)                                                                                                                                                       
      File "alembic/alembic/autogenerate/compare.py", line 82, in _compare_tables                                                                                                        
        for s, tname in sorted(existing_tables):                                                                                                                                    
    TypeError: unorderable types: NoneType() < quoted_name()                                                                                                                                               
  2. Mike Bayer repo owner

    OK it is very interesting that our tests aren't picking this up. We have schema level tests for PG and we run them in Py3K. More tests will need to be added to catch this.

  3. paradoxxxzero author

    This is because in the autogenerate tests there's never two already existing tables with different schemas with one being the default.

    I added two tables in the AutogenCrossSchemaTest that show the error.

  4. Mike Bayer repo owner

    that's great! thanks very much. I have a list of PRs to get to including for alembic, this is in the list ( I try to do them in batches every couple of weeks).