[Modeling-cvs] SF.net SVN: modeling: [992] trunk/ProjectModeling/Modeling/doc/bug861048.txt
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2006-04-15 09:45:08
|
Revision: 992 Author: sbigaret Date: 2006-04-15 02:44:54 -0700 (Sat, 15 Apr 2006) ViewCVS: http://svn.sourceforge.net/modeling/?rev=992&view=rev Log Message: ----------- was not under subversion control Added Paths: ----------- trunk/ProjectModeling/Modeling/doc/bug861048.txt Added: trunk/ProjectModeling/Modeling/doc/bug861048.txt =================================================================== --- trunk/ProjectModeling/Modeling/doc/bug861048.txt (rev 0) +++ trunk/ProjectModeling/Modeling/doc/bug861048.txt 2006-04-15 09:44:54 UTC (rev 992) @@ -0,0 +1,77 @@ +Bug #861048: Invalid FK constraints in generated DB schema +========================================================== + +:Author: `S\xE9bastien Bigaret`_ + +.. _`S\xE9bastien Bigaret`: mailto:Seb...@en... + + +The bug described here cannot only be fixed with a patch against the `Modeling +framework` because it affects database schemas that have been created by the +framework v0.9pre16 or earlier versions. Worse, **it can lead to silent data +loss when used with postgresql and the ``psycopg`` python adaptor**. + +You'll find here a full description of the bug, along with instructions on how +existing database schemas can be fixed. + + +.. _`Modeling framework`: http://modeling.sourceforge.net + +.. contents:: + +Description of the bug +---------------------- + +Generation of the database schema sometimes produces foreign key constraints +that are invalid wrt the model. + +This happens when the model has a to-one relationship pointing to an +entity which has at least a sub-entity. Such a model:: + + model.version='0.1' + model.entities = [ # A-------- b -->B + Entity('A'), # / \ + Entity('B'), # /-+-\ + Entity('C', parent='B'), # | + ] # | + model.associations=[ # C + Association('A','B', relations=['b', 'as'] ), + ] + +generates a database schema which contains:: + + [...] + ALTER TABLE A ADD CONSTRAINT b FOREIGN KEY (FK_B) \ + REFERENCES B(ID) INITIALLY DEFERRED; + [...] + +This constraint is not valid, because an instance of ``A`` could reference +either a ``B`` or a ``C``. + +:Consequence: + Since some FK constraint is invalid, you will not be able to save changes in + an ``EditingContext`` when an ``A`` is in relation to a ``C``, just because + this violates the constraint. + + +Possible data loss with ``psycopg`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Now if you use Postgresql and ``psycopg``, the problem is that this bug hits +an other bug in psycopg v1.1.10 or earlier, where errors at commit time are +silently ignored. As a consequence, if you save changes on an +``EditingContext`` which as an ``A`` in relation to a ``C``, the postgresql +database server will reject the commit (because of the buggy FK +constraint). But ``psycopg`` silently ignores the exception, as a consequence +**the changes appears to be safe but none of the changes was committed in the +database**. + +For this reason, it is strongly recommended to ``psycopg`` users to upgrade +their copy to v1.1.11 or higher + +For more details, please refer the corresponding thread in the `psycopg +archives +<http://lists.initd.org/pipermail/psycopg/2003-December/002432.html>`__. + +Fixing the database schema +-------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |