Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/vocabularies.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/vocabularies.py	(revision 8765)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/vocabularies.py	(revision 8766)
@@ -140,8 +140,19 @@
 
 class RegNumberSource(object):
+    """A source that accepts any entry for a certain field if not used
+    already.
+
+    Using this kind of source means a way of setting an invariant.
+
+    We accept a value iff:
+    - the value cannot be found in catalog or
+    - the value can be found as part of some item but the bound item
+      is the context object itself.
+    """
     implements(ISource)
     cat_name = 'students_catalog'
     field_name = 'reg_number'
     validation_error = RegNumNotInSource
+    comp_field = 'student_id'
     def __init__(self, context):
         self.context = context
@@ -149,4 +160,6 @@
 
     def __contains__(self, value):
+        """We accept all values not already given to other students.
+        """
         cat = queryUtility(ICatalog, self.cat_name)
         if cat is None:
@@ -155,8 +168,15 @@
         results = cat.searchResults(**kw)
         for entry in results:
-            if entry.student_id != self.context.student_id:
-                # XXX: sources should simply return False.
-                #      But then we get some stupid error message in forms
-                #      when validation fails.
+            if not hasattr(self.context, self.comp_field):
+                # we have no context with comp_field (most probably
+                # while adding a new object, where the container is
+                # the context) which means that the value was given
+                # already to another object (as _something_ was found in
+                # the catalog with that value). Fail on first round.
+                raise self.validation_error(value)
+            if getattr(entry, self.comp_field) != getattr(
+                self.context, self.comp_field):
+                # An entry already given to another student is not in our
+                # range of acceptable values.
                 raise self.validation_error(value)
                 #return False
