Use viewonly=True to suppress relationship warnings in SQLA 1.4

This commit is contained in:
Parnassius 2021-12-11 16:18:11 +01:00
parent 62c8ca421a
commit 716ad75dbc
2 changed files with 8 additions and 0 deletions

View file

@ -185,6 +185,7 @@ def create_translation_table(_table_name, foreign_class, relation_name,
foreign_keys=[Translations.foreign_id, Translations.local_language_id],
uselist=False,
lazy=relation_lazy,
viewonly=True,
))
# Add per-column proxies to the original class

View file

@ -30,6 +30,7 @@ from functools import partial
import six
from sqlalchemy import Column, ForeignKey, MetaData, PrimaryKeyConstraint, UniqueConstraint
from sqlalchemy import __version__ as sqla_version
from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.hybrid import hybrid_property
@ -39,6 +40,12 @@ from sqlalchemy.types import Boolean, Enum, Integer, SmallInteger, Unicode, Unic
from pokedex.db import markdown, multilang
relationship = partial(relationship, viewonly=True)
if (1, 3, 17) <= tuple(int(x) for x in sqla_version.split(".")) < (1, 4):
# `sync_backref` was introduced in 1.3.17
# Since 1.4 it defaults to False if `viewonly` is True
relationship = partial(relationship, sync_backref=False)
class TableSuperclass(object):
"""Superclass for declarative tables, to give them some generic niceties
like stringification.