Django

Code

Changeset 4125

Show
Ignore:
Timestamp:
11/27/06 21:45:50 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Fixed bug in handling of inter-app pending statements on syncdb.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multiple-db-support/django/core/management.py

    r4123 r4125  
    293293 
    294294    # Install each app 
     295    pending = None 
    295296    for app in models.get_apps(): 
    296297        # Install each application (models already installed will be skipped) 
    297         created = _install(app, commit=False, initial_data=False) 
     298        created, pending = _install(app, commit=False, initial_data=False, 
     299                                    pending_allowed=True, pending=pending) 
    298300        if verbosity >= 2: 
    299301            for model in created: 
    300302                print "Created table %s" % model._meta.db_table 
    301303        created_models.extend(created) 
     304    if pending: 
     305        transaction.rollback_unless_managed() 
     306        raise Exception("All apps were installed, but there were still " 
     307                        "pending references to: " + ",".join(pending.keys()) + 
     308                        ". Transaction rolled back.") 
    302309    transaction.commit_unless_managed() 
    303310 
     
    384391    _install(app) 
    385392 
    386 def _install(app, commit=True, initial_data=True): 
     393def _install(app, commit=True, initial_data=True, pending_allowed=False, 
     394             pending=None): 
    387395    from django.db import connection, models, transaction 
    388396    import sys 
     
    397405    created_models = [] 
    398406    try: 
    399         pending = {} 
     407        if pending is None: 
     408            pending = {} 
    400409        for model in models.get_models(app, creation_order=True): 
    401410            manager = model._default_manager 
     
    418427                            statement.execute() 
    419428                    pending.pop(model) 
    420                 else
     429                elif not pending_allowed
    421430                    raise Exception("%s is not installed, but it has pending " 
    422431                                    "references" % model) 
     
    434443    if commit: 
    435444        transaction.commit_unless_managed() 
    436     return created_models 
     445    return created_models, pending 
    437446install.help_doc = "Executes ``sqlall`` for the given app(s) in the current database." 
    438447install.args = APP_ARGS