dtolabs / yana2

Yet Another Node Authority ... because you wanted an agile Real-Time Service Model (RTSM)
8 stars 1 forks source link

NodeType DELETE not possible if TemplateAttributes still associated #130

Open ahonor opened 12 years ago

ahonor commented 12 years ago

To reproduce:

Response:

        <h1>Error 500: Internal Server Error</h1>
<dl class="error-details">
<dt>URI</dt><dd>/api/nodeType/none/1</dd>
<dt>Class</dt><dd>org.h2.jdbc.JdbcSQLException</dd><dt>Message</dt><dd>Referential integrity constraint violation: &quot;FKCC31A117448F1C42: PUBLIC.TEMPLATE_ATTRIBUTE FOREIGN KEY(TEMPLATE_ID) REFERENCES PUBLIC.NODE_TYPE(ID)&quot;; SQL statement:
delete from node_type where id=? and version=? [23003-147]</dd></dl><h2>Trace</h2><pre class="stack">   Line | Method
-&gt;&gt; 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   908 | run     in     &#39;&#39;
^   680 | run . . in java.lang.Thread

Caused by ConstraintViolationException: could not delete: [com.dtosolutions.NodeType#1]
-&gt;&gt; 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
ahonor commented 12 years ago

Actually, it appears it is not possible to delete a NodeType from the GUI as well.

A flash message appears when trying to delete: "NodeType 5 could not be deleted"

Note, this is true even for types that have no Node instances.

ahonor commented 12 years ago

Further investigation shows that any NodeType that has associated TemplateAttributes cannot be deleted. (i.e., a NodeType w/o associated attributes can be deleted).

orubel commented 12 years ago

Yes you have to delete associations unless you want an unchecked cascade,... which is dangerous. I can put in more CLEAR error messages if this is what you want but this needs to be specified as to whether the CASCADE DELETE with transactional rollback is wanted or whether CLEARER OUTPUT MESSAGES are or both. At which point this will most likely be all I do today.

orubel commented 12 years ago

what needs to be done is make sure their is no 'dependson' between node and nodetype so all you have to do is CHECK whether a node nodetype exists in a node or not up front (outside the transaction); this is our main test and needs to happen upfront and outside the transaction as it is easier and doesnt need to happen within transaction since we would never commit this regardless if it existed. Then do a transactional delete through the dependencies (nodetype > templateattribute > templatevalue) and rollback on any fail.