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.

Peewee+PSQL: create_tables for complex object relationships broken when DeferredRelations in play

See original GitHub issue

As in the docs, circular FK dependencies are a code smell, and I agree, but here we are. I’ve got a big object domain with some of these objects having circular foreign keys.

In peewee versions in the 2.8 line, create_tables seemed to be able to resolve any DeferredRelations used for circular FK relationships and tell PSQL to create the tables appropriately. I see in the docs that there’s a more manual approach documented, but I’ve never encountered need for it until upgrading from 2.8.x to 2.10.x.

Two questions:

  1. Am I correct in finding that the behavior of automatically doing this was done by peewee prior, and is now no longer supported? (otherwise, what magic could it have been that made this work before?)
  2. Do you have any recommended methods for enabling a more opinionated methodology to creating tables in this way, or automating the process as documented? My CI environment does a build/teardown of tables every run (sometimes every test) and I’m thinking that having a special codepath for each DeferredRelation’s setup is a little unclean.

I know it’s a way uncommon use-case (and a noncurrent version on top of that), but I’m hoping you might have some top-of-the-head insight as to what in particular changed; the changelog between the versions don’t really show anything that appears related.

As always, thanks for your continued work and support on this tool – it’s a wonderful piece of tech.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Feb 27, 2018

Hmm… it looks like changes to the way deferred foreign-keys were resolved, although there are quite a few changes so I’m not positive.

At any rate, I don’t think there’s a whole lot I can offer, as Peewee is now at 3.x and any fixes would pertain to how the code functions in 3.x (which is somewhat different from 2.10). Sorry not to be of more help.

0reactions
josefdlangecommented, Feb 27, 2018

I appreciate your help with the investigation. I’m looking to get to 3.x eventually, but wanted to understand what was going wrong here before I opened that can of worms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relationships and Joins — peewee 3.15.4 documentation
In this document we'll cover how Peewee handles relationships between models. ... Peewee allows you to join on any table-like object, including subqueries ......
Read more >
Introduction to Peewee and Relations | by Prabhath kiran
Peewee is a simple and small ORM. It is easy to use and gets the job done. What is covered in this post....
Read more >
PEEWEE(1) - Linux man page online | User commands
db.connect() We'll begin by creating the tables in the database that will store ... .where(Relationship.to_user == self)) Creating new objects When a new ......
Read more >
peewee/api.rst at master · coleifer ...
Example:: def on_app_startup(): # When app starts up, create the database tables, being sure # the connection is closed upon completion. with ...
Read more >
SQL (Relational) Databases with Peewee - FastAPI
When you access a relationship in a Peewee object, like in some_user.items , Peewee doesn't provide ... In a very simplistic way create...
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