Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Before Testing #544

Closed
ptth222 opened this issue Feb 29, 2024 · 1 comment
Closed

Installation Before Testing #544

ptth222 opened this issue Feb 29, 2024 · 1 comment
Assignees

Comments

@ptth222
Copy link

ptth222 commented Feb 29, 2024

I have been running the tests locally on my machine to try and track down some of problems with my PRs, and I found an issue. Initially, I had a problem because I was installing the package from the local files before trying to test and this causes the file paths to the testing data to be incorrect. After figuring that out I ran into a problem with the version of SQLAlchemy that was installed. Apparently, higher versions of that package won't work. The root cause of the version difference came from first installing the whole package vs what the GitHub workflow does, which is to install what's in the requirements file.

The current GitHub workflow used for testing does not actually install the package and test the installed package, it tests the local files. In general, I don't recommend this because it doesn't mimic what a user will do. I ran into this with one of my packages in the past and changed my workflow so it installs the package and tests the installed package. Case in point with what happened to me here. When I installed the package I got a different version of SQLAlchemy than what you get if you just install what's in the requirements file which changes how the tests behave. Note that this was in a new virtual environment, so the only command that installed SQLAlchemy was the one to install the package from the local files.

The specific traceback from tests\database\test_model.py was:

Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python310\lib\unittest\__main__.py", line 18, in <module>
    main(module=None)
  File "C:\Python310\lib\unittest\main.py", line 100, in __init__
    self.parseArgs(argv)
  File "C:\Python310\lib\unittest\main.py", line 147, in parseArgs
    self.createTests()
  File "C:\Python310\lib\unittest\main.py", line 158, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames,
  File "C:\Python310\lib\unittest\loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\Python310\lib\unittest\loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\Python310\lib\unittest\loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "C:\Users\Sparda\Desktop\Moseley Lab\Code\isa-api\tests\database\test_model.py", line 5, in <module>
    from isatools.database import *
  File "C:\Users\Sparda\Desktop\Moseley Lab\Code\isa-api\isatools\database\__init__.py", line 13, in <module>
    from isatools.database.models import (
  File "C:\Users\Sparda\Desktop\Moseley Lab\Code\isa-api\isatools\database\models\__init__.py", line 1, in <module>
    from isatools.database.models.comment import (
  File "C:\Users\Sparda\Desktop\Moseley Lab\Code\isa-api\isatools\database\models\comment.py", line 10, in <module>
    class Comment(Base):
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\flask_sqlalchemy\model.py", line 100, in __init__
    super().__init__(name, bases, d, **kwargs)
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\flask_sqlalchemy\model.py", line 120, in __init__
    super().__init__(name, bases, d, **kwargs)
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_api.py", line 196, in __init__
    _as_declarative(reg, cls, dict_)
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 244, in _as_declarative
    return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 325, in setup_mapping
    return _ClassScanMapperConfig(
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 560, in __init__
    self._scan_attributes()
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 1003, in _scan_attributes
    collected_annotation = self._collect_annotation(
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 1274, in _collect_annotation
    extracted = _extract_mapped_subtype(
  File "C:\Users\Sparda\Desktop\venv\venv\lib\site-packages\sqlalchemy\orm\util.py", line 2380, in _extract_mapped_subtype
    raise sa_exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Type annotation for "Comment.assay" can't be correctly interpreted for Annotated Declarative Table form.  ORM annotations should normally make use of the ``Mapped[]`` generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[].  To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "__allow_unmapped__ = True" on the class or a superclass this class. (Background on this error at: https://sqlalche.me/e/20/zlpr)

SQLAlchemy version 2.0.27 was what was installed and downgrading to 1.4.51 fixed the issue.

@proccaserra
Copy link
Member

@ptth222 thx for reporting, now fixed with PR #564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants