question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimisation assertion error for Pydantic library

See original GitHub issue

Hi, I’m getting the following assertion error around optimizer while compiling a project that uses Pydantic

The System

MacOS Catalina
Python 3.7.6 (default, Jan  6 2020, 14:21:53) [Clang 7.1.0 (tags/RELEASE_710/final)] on darwin

Nuitka build:

0.6.7
Python: 3.7.6 (default, Jan  6 2020, 14:21:53) 
Executable: /Users/project/.venv/bin/python
OS: Darwin
Arch: x86_64

The environment with Python is created by the following Nix shell:

with (import (builtins.fetchGit {
    # https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
    name = "nuitka-python37";
    url = https://github.com/nixos/nixpkgs/;
    ref = "refs/heads/master";
    rev = "6f545410b593a0d1b78806aa878f95ee3f3d4a4a";
}) {});

mkShell {
    name = "nuitka-python37-python37";
    buildInputs = [
        # see https://nixos.org/nixos/packages.html
        # Python distribution
        python37Full
        python37Packages.virtualenv
        poetry
        # usually required as python runtime dependencies
        ncurses
        libxml2
        libxslt
        libzip
        zlib
        # root CA certificates
        cacert
        gnumake
        which
    ];
    shellHook = ''
        # Set SOURCE_DATE_EPOCH so that we can use python wheels.
        # This compromises immutability, but is what we need
        # to allow package installs from PyPI
        export SOURCE_DATE_EPOCH=$(date +%s)

        VENV_DIR=$PWD/.venv

        export PATH=$VENV_DIR/bin:$PATH
        export PYTHONPATH=""
        export LANG=en_US.UTF-8

        # https://python-poetry.org/docs/configuration/
        export POETRY_VIRTUALENVS_CREATE=true
        export POETRY_VIRTUALENVS_IN_PROJECT=true
        export PIP_CACHE_DIR=$PWD/.local/pip-cache

        # Setup virtualenv
        if [ ! -d $VENV_DIR ]; then
            virtualenv $VENV_DIR
        fi

        # Dirty fix for Linux systems
        # https://nixos.wiki/wiki/Packaging/Quirks_and_Caveats
        export LD_LIBRARY_PATH=${stdenv.cc.cc.lib}/lib/:$LD_LIBRARY_PATH
    '';
}

The traceback is:

Nuitka:INFO:Optimizing module 'pydantic', 13 more modules to go after that.
Nuitka:INFO:Doing module local optimizations for 'pydantic'.
Traceback (most recent call last):
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/__main__.py", line 182, in <module>
    main()
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/__main__.py", line 175, in main
    MainControl.main()
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/MainControl.py", line 736, in main
    main_module = createNodeTree(filename=filename)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/MainControl.py", line 142, in createNodeTree
    Optimization.optimize(main_module.getOutputFilename())
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/optimizations/Optimization.py", line 619, in optimize
    finished = makeOptimizationPass(initial_pass=False)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/optimizations/Optimization.py", line 530, in makeOptimizationPass
    changed = optimizeModule(current_module)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/optimizations/Optimization.py", line 168, in optimizeModule
    changed = optimizeCompiledPythonModule(module)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/optimizations/Optimization.py", line 127, in optimizeCompiledPythonModule
    Plugins.considerImplicitImports(module=module, signal_change=signalChange)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/plugins/Plugins.py", line 141, in considerImplicitImports
    plugin.considerImplicitImports(module, signal_change)
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/plugins/PluginBase.py", line 207, in considerImplicitImports
    signal_change=signal_change,
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/plugins/PluginBase.py", line 498, in recurseTo
    reason=reason,
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/importing/Recursion.py", line 167, in recurseTo
    reason=reason,
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/importing/Recursion.py", line 83, in _recurseTo
    is_shlib=module_kind == "shlib",
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/tree/Building.py", line 924, in decideModuleTree
    source_ref=source_ref,
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/nodes/ModuleNodes.py", line 264, in __init__
    setLocalsDictType(self.module_dict_name, "module_dict")
  File "/Users/project/.venv/lib/python3.7/site-packages/nuitka/nodes/LocalsScopes.py", line 31, in setLocalsDictType
    assert locals_dict_name not in locals_dict_handles, locals_dict_name
AssertionError: globals_pydantic$__init__

The application:

import pydantic


if __name__ == "__main__":
    print('Hello world!')

Build script:

python -m nuitka --show-progress --follow-imports ./nuitka-app.py

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, May 21, 2020

I am getting the similar import error for these ones as in #689 and I think pydantic has worked before, so there must also be a regression in that.

0reactions
kayhayencommented, May 23, 2020

So this one also is all extension modules on me now, too, leading to no compilation at all. With the ```–prefer-source-code`` option we are getting also no error anymore.

And now I recall it was a problem with imports not being understood properly, leading to some form of duplication and this was solved in #618 long time ago, and with 0.6.8 was released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Validate Your Data with Custom Validators of Pydantic ...
If the type of a property cannot be coerced, a ValidationError will be raised together with some helpful error messages which are very...
Read more >
Validators - pydantic
validators should either return the parsed value or raise a ValueError , TypeError , or AssertionError ( assert statements may be used). Warning....
Read more >
Pydantic - The Blue Book
Pydantic is a data validation and settings management using python type annotations. pydantic enforces type hints at runtime, and provides user friendly errors...
Read more >
Pydantic V2 Plan
If the input data has a SINGLE and INTUITIVE representation, in the field's type, AND no data is lost during the conversion, then...
Read more >
Pydantic Hidden Features - Gideon's Blog -
Pydantic is a great Python library for parsing & validation. ... accumulates all the errors using ValidationError and is well documented ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found