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

Switch Metric-Resource relationship to back_populates #1393

Merged

Conversation

Callum027
Copy link
Contributor

Replace usage of the deprecated backref option [1] and implicit relationship population, with the new back_populates [2] option and explicit relationship definitions on both the Metric and Resource classes.

This eliminates "AttributeError: type object 'Metric' has no attribute 'resource'" exceptions that can occur when Metric.resource is referenced using sqlalchemy.orm.joinedload in queries.

This change is backwards compatible with SQLAlchemy 1.4.

1: https://docs.sqlalchemy.org/en/20/orm/backref.html
2: https://docs.sqlalchemy.org/en/20/orm/basic_relationships.html

@Callum027
Copy link
Contributor Author

Originally encountered while troubleshooting a separate issue with python-gnocchiclient.

gnocchixyz/python-gnocchiclient#142 (comment)

@Callum027
Copy link
Contributor Author

Test failing because of an unrelated dependency toolchain issue with the version of pkg_resources (and jaraco.text) being used.

Traceback (most recent call last):
  File "/github/workspace/.tox/py39-postgresql-file-upgrade-from-4.4/bin/gnocchi", line 5, in <module>
    from gnocchiclient.shell import main
  File "/github/workspace/.tox/py39-postgresql-file-upgrade-from-4.4/lib/python3.9/site-packages/gnocchiclient/shell.py", line 40, in <module>
    from gnocchiclient.version import __version__
  File "/github/workspace/.tox/py39-postgresql-file-upgrade-from-4.4/lib/python3.9/site-packages/gnocchiclient/version.py", line 15, in <module>
    import pkg_resources
  File "/github/workspace/.tox/py39-postgresql-file-upgrade-from-4.4/lib/python3.9/site-packages/pkg_resources/__init__.py", line 96, in <module>
    from jaraco.text import (
ImportError: cannot import name 'yield_lines' from 'jaraco.text' (/usr/lib/python3/dist-packages/jaraco/text/__init__.py)
py39-postgresql-file-upgrade-from-4.4: exit 1 (45.47 seconds) /github/workspace> run-upgrade-tests.sh postgresql-file pid=120
  py39-postgresql-file-upgrade-from-4.4: FAIL code 1 (52.61=setup[7.14]+cmd[45.47] seconds)
  evaluation failed :( (52.67 seconds)

chungg
chungg previously approved these changes Aug 13, 2024
Replace usage of the deprecated backref option [1]
and implicit relationship population, with the new
back_populates [2] option and explicit relationship
definitions on both the Metric and Resource classes.

This eliminates
"AttributeError: type object 'Metric' has no attribute 'resource'"
exceptions that can occur when Metric.resource is referenced
using sqlalchemy.orm.joinedload in queries.

This change is backwards compatible with SQLAlchemy 1.4.

1: https://docs.sqlalchemy.org/en/20/orm/backref.html
2: https://docs.sqlalchemy.org/en/20/orm/basic_relationships.html
@Callum027 Callum027 force-pushed the metric-resource-relationship-fix branch from c5b0df8 to 287092d Compare August 15, 2024 19:08
@mergify mergify bot dismissed chungg’s stale review August 15, 2024 19:08

Pull request has been modified.

@tobias-urdin tobias-urdin merged commit 3e84ca5 into gnocchixyz:master Aug 16, 2024
23 checks passed
@Callum027 Callum027 deleted the metric-resource-relationship-fix branch August 19, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants