Ok never mind!
I realized I could scrap this entire functionality and replace it with
something else.
The use-case was trying to detect the backup renewal options for SSL
Certificates if the private key Or account key is revoked. (foo is an ACME
order if available, bar is the certificate).
I have two classes where one f-keys onto another.
Things work perfectly:
class Foo(Base):
id = Column(Integer, primary_key=True)
bar_id = Column(Integer, ForeignKey("bar.id"), nullable=True)
bar = relationship(
"bar",
primaryjoin="Foo.bar_id==Bar.id",