elpaso / django-dag

Basic portable Directed Acyclic Graph application for Django
66 stars 19 forks source link

TypeError: save() got an unexpected keyword argument 'disable_circular_check' [migrations] #25

Closed math-a3k closed 7 years ago

math-a3k commented 7 years ago
(ENV) rodrigo@enoch:~/code/pkgs/ckctr/django-ai/django_ai$ python manage.py migrate examples
System check identified some issues:

WARNINGS:
bayesian_networks.BayesianNetworkNode.children: (fields.W340) null has no effect on ManyToManyField.
Operations to perform:
  Apply all migrations: examples
Running migrations:
  Applying examples.0004_bn_example...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/rodrigo/code/pkgs/ckctr/django-ai/django_ai/examples/migrations/0004_bn_example.py", line 57, in create_bn1_example
    mu.add_child(ui_avg1, description="mu -> userinfo.avg1")
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django_dag/models.py", line 42, in add_child
    return cls.save(disable_circular_check=disable_check)
TypeError: save() got an unexpected keyword argument 'disable_circular_check'

The migrations:

# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-02 20:29
from __future__ import unicode_literals

from django.db import migrations

from bayesian_networks.bayespy_constants import (
    DIST_GAUSSIAN_ARD, DIST_GAMMA)
from bayesian_networks.models import BayesianNetworkNode as BNN

def create_bn1_example(apps, schema_editor):
    BayesianNetwork = apps.get_model("bayesian_networks",
                                     "BayesianNetwork")
    BayesianNetworkEdge = apps.get_model("bayesian_networks",
                                         "BayesianNetworkEdge")
    BayesianNetworkNode = apps.get_model("bayesian_networks",
                                         "BayesianNetworkNode")
    ContentType = apps.get_model("contenttypes",
                                "ContentType")

    bn1 = BayesianNetwork(name="BN1 (Example)")
    bn1.save()
    # import ipdb; ipdb.set_trace()
    mu = BayesianNetworkNode(
        network=bn1,
        name="mu",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=False,
        distribution=DIST_GAUSSIAN_ARD,
        distribution_params="0, 1e-6",
        graph_interval="-10, 20"
    )
    tau = BayesianNetworkNode(
        network=bn1,
        name="tau",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=False,
        distribution=DIST_GAMMA,
        distribution_params="1e-6, 1e-6",
        graph_interval="1e-6, 1"
    )
    ui_avg1 = BayesianNetworkNode(
        network=bn1,
        name="userinfo.avg1",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=True,
        distribution=DIST_GAUSSIAN_ARD,
        distribution_params="mu, tau",
        ref_model=ContentType.objects.get(model="userinfo",
                                          app_label="examples"),
        ref_column="avg1",

    )
    tau.save()
    mu.save()
    ui_avg1.save()
    mu.add_child(ui_avg1, description="mu -> userinfo.avg1")
    tau.add_child(ui_avg1, description="tau -> userinfo.avg1")

However, using

    mu_to_ui_avg1 = BayesianNetworkEdge(
        network=bn1,
        description="mu -> userinfo.avg1",
        parent=mu,
        child=ui_avg1
    )
    mu_to_ui_avg1.save()

works, so for some reason the API shown in tests.py does not work in migrations.

math-a3k commented 7 years ago

For the sake of documentation, model methods don't work in migrations, if you run into this - a data migration with django-dag - use the class constructor instead of the """model api""" or method.

This is not a bug, just a caveat