Commits

Andrew Godwin  committed cbad442

Fix #300 and make a massive warning appear for unintrospectable fields.

  • Participants
  • Parent commits 1e6d1da
  • Branches 0.7

Comments (0)

Files changed (3)

File south/creator/actions.py

     @classmethod
     def triple_to_def(cls, triple):
         "Turns a single triple into a definition."
-        triple = remove_useless_attributes(triple, db=True)
-        if triple is None:
-            print "WARNING: Cannot get definition for '%s' on '%s'. Please edit the migration manually." % (
-                field,
-                model_key(model),
-            )
-            return "<<??>>"
-        else:
-            return "self.gf(%r)(%s)" % (
-                triple[0], # Field full path
-                ", ".join(triple[1] + ["%s=%s" % (kwd, val) for kwd, val in triple[2].items()]), # args and kwds
-            )
+        return "self.gf(%r)(%s)" % (
+            triple[0], # Field full path
+            ", ".join(triple[1] + ["%s=%s" % (kwd, val) for kwd, val in triple[2].items()]), # args and kwds
+        )
     
     
 class AddModel(Action):
         )
 
     def forwards_code(self):
-        
+        "Produces the code snippet that gets put into forwards()"
         field_defs = ",\n            ".join([
             "(%r, %s)" % (name, defn) for name, defn
             in self.triples_to_defs(self.model_def).items()
         }
 
     def backwards_code(self):
+        "Produces the code snippet that gets put into backwards()"
         return self.BACKWARDS_TEMPLATE % {
             "model_name": self.model._meta.object_name,
             "table_name": self.model._meta.db_table,

File south/creator/freezer.py

 Handles freezing of models into FakeORMs.
 """
 
+import sys
+
 from django.db import models
 from django.contrib.contenttypes.generic import GenericRelation
 
     model_defs = {}
     for model in frozen_models:
         model_defs[model_key(model)] = prep_for_freeze(model)
+    # Check for any custom fields that failed to freeze.
+    missing_fields = False
+    for key, fields in model_defs.items():
+        for field_name, value in fields.items():
+            if value is None:
+                missing_fields = True
+                print " ! Cannot freeze field '%s.%s'" % (key, field_name)
+    if missing_fields:
+        print ""
+        print " ! South cannot introspect some fields; this is probably because they are custom"
+        print " ! fields. If they worked in 0.6 or below, this is because we have removed the"
+        print " ! models parser (it often broke things)."
+        print " ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork"
+        sys.exit(1)
+    
     return model_defs
     
 def freeze_apps_to_string(apps):

File south/modelsinspector.py

 from django.contrib.contenttypes import generic
 from django.utils.datastructures import SortedDict
 
-NOISY = True
+NOISY = False
 
 # Gives information about how to introspect certain fields.
 # This is a list of triples; the first item is a list of fields it applies to,
             field_defs[field.name] = field.south_field_triple()
         # Can we introspect it?
         elif can_introspect(field):
-            #if NOISY:
-            #    print "Introspecting field: %s" % field.name
             # Get the full field class path.
             field_class = field.__class__.__module__ + "." + field.__class__.__name__
             # Run this field through the introspector