Open vector-kerr opened 3 years ago
Were you able to resolve this?
Unfortunately not, sorry @iamprakashom .
1. Circular Dependency Issue
I found this occurs when BOTH the initial user account migration AND the django-organizations migrations are being generated at the same time.
We found ourselves in this scenario this after doing some refactoring before our first production release (we hosed all the migrations with the intention of just re-creating all migrations from scratch (after changing a few module names etc)) The solution for us was to comment out all mention of django-organizations, then run makemigrations so it only picks up the custom auth user model (and any other unrelated) ... THEN uncomment organizations back in and run makemigrations again.
2. weird output - a migration is created against the organizations module in the virtual environment
Yes, we nearly missed this before release to staging etc.
We don't commit the virtual environment to source control - as is typical, but do run makemigrations
as part of the commit cycle so the migrations are under source control.
But in doing so, these migrations are lost between DEV and other environments if makemigrations
is not run.
As I understand it....
Option A. It's possible to override migration lookups for django apps by configuring:
MIGRATION_MODULES = {
'organizations': 'my_app.extra_migrations.organizations'
}
BUT then you have to copy the original ones into here, before running makemigrations
BUT when you upgrade django-organizations and any new migrations comes in - for a fix or feature - then you'll miss these unless you look out for them and copy new ones over manually
EDIT: to keep on top of this, we have a small script inside my_app.extra_migrations.organizations.__init__.py
import pkgutil
from organizations import migrations as vendor_migrations
local_migrations = [x.name for x in pkgutil.iter_modules(__path__)]
for vendor_migration in pkgutil.iter_modules(vendor_migrations.__path__):
if vendor_migration.name not in local_migrations:
print("WARNING !! django-organizations has new migrations: ", vendor_migration.name)
Option B. commit .venv into source control.
Neither option seems brilliant.
good luck
Thanks for this. Splitting up into two sets of migrations worked well. Luckily commenting all the stuff out was a viable option for me. Don't know what I would have done if had had a bunch of code to isolate.
This should really be fixed
This should really be fixed
@pfcodes would you mind rewording that in the active voice?
The folks on this issue thread have put work into describing the issue they've encountered. I for one would heartily welcome a pull request to resolve this issue, and if you'd like to put in the work it will be most welcome!
Following the exact example by @vector-kerr above reproduces the exact issue as described.
core
depends on the latest migration from organizations
makemigrations
fails with circular dependency issuesAmending the example to instead include the custom user model in a separate users
app - i.e. defining the custom user model in a separate app from the organizations - resolves the problem entirely.
core
depends on the latest migration from organizations
users
depends on the latest migration from auth
makemigrations
simply report that there are no changes detectedIt's hard to know if the example is just contrived for simplicity (which is completely reasonable) or representative of typical use. However given what I've seen here and what I've seen in the migrations, my current suspicion is that this is the case.
The initial organizations
migration includes a swappable dependency on the AUTH_USER_MODEL
and if that model is defined in the same app as models that in turn depend on on it then 💥 circular dependency.
I've never included custom users in the same app as custom organizations and so never even thought to ask if that was the production use case. If it is I would gently recommend against doing that, this issue notwithstanding. However if that is the common scenario then the solution here is going to be installation guidelines, because I do not think there is any code solution to the issue as described.
Hey @bennylope, thank you for taking the time to look into this!
It's been quite some time since I encountered this issue, but from what I can recall, I was trying to stand up a basic use case, hence the all-in-one-app.
If it doesn't exist, some guidelines or a note to indicate that custom users should exist in a separate app would probably be more than sufficient to consider this done.
Thanks again!
Greetings!
I'm having a go at using
django-organizations
, and I've been getting a circular reference error when attempting to perform migrations, which I believe I can trace back todjango-organizations
and using a customAUTH_USER_MODEL
.I say 'I believe' because I'm not 100% sure that I haven't done something incorrectly, but having read the documentation on using a custom user model and proxy models, I think I've covered myself...
I've included a set of steps to reproduce below which should hopefully demonstrate that either I'm doing something woefully wrong, or there's something weird going on with custom user models.
If you need any more information, or if I've stupidly broken it somehow, please let me know. :)
Thanks for your help and your time! - Vector
Steps to reproduce
demo
) and enter the directory:core
which will be used for models and migrationsPut the following content into
core/models.py
:Update
demo/settings.py
to include theorganizations
andcore
apps, and set the custom user model:At this point, I get the first bit of weird output - a migration is created against the
organizations
module in the virtual environment: