Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null id in InvoicingItem when calling update() #3

Closed
dellermann opened this issue Nov 23, 2013 · 7 comments
Closed

null id in InvoicingItem when calling update() #3

dellermann opened this issue Nov 23, 2013 · 7 comments
Assignees
Milestone

Comments

@dellermann
Copy link
Owner

A user reported an exception when updating a quote. The error seems to be caused by added invoicing items and updating the invoicing transaction (here: the quote).

Error report

<?xml version="1.0"?>

<error-report xmlns="http://www.amc-world.de/data/xml/springcrm"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.amc-world.de/data/xml/springcrm http://www.amc-world.de/data/xml/springcrm/error-report-1.1.xsd">
  <report-version>1.1</report-version>
  <application>
    <version>1.2.5</version>
    <build-number>1489</build-number>
    <build-date>2012-11-29T16:00:52+0100</build-date>
    <build-profile>live</build-profile>
  </application>
  <customer>
    <name>Robert</name>
    <email>r.kirchner@amc-world.de</email>
  </customer>
  <description></description>
  <details>
    <status-code>500</status-code>
    <message>null id in org.amcworld.springcrm.InvoicingItem entry (don't flush the Session after an exception occurs)</message>
    <servlet>grails</servlet>
    <uri>/springcrm/grails/quote/update.dispatch</uri>
  </details>
  <exception>
    <message>null id in org.amcworld.springcrm.InvoicingItem entry (don't flush the Session after an exception occurs)</message>
    <caused-by>null id in org.amcworld.springcrm.InvoicingItem entry (don't flush the Session after an exception occurs)</caused-by>
    <class-name>LruFilters</class-name>
    <line-number>68</line-number>
    <code-snippet>

    </code-snippet>
    <stack-trace>
    org.hibernate.AssertionFailure: null id in org.amcworld.springcrm.InvoicingItem entry (don't flush the Session after an exception occurs)
    at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1591)
    at org.amcworld.springcrm.LruService.recordItem(LruService.groovy:57)
    at org.amcworld.springcrm.LruFilters$_closure1_closure3_closure6.doCall(LruFilters.groovy:68)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
    </stack-trace>
  </exception>
</error-report>

Relates to Bugzilla bug 268.

@dellermann
Copy link
Owner Author

I think the error occurs when new invoicing items with id == null are stored. Then some methods as hashCode() throw an NPE.

@dellermann
Copy link
Owner Author

I recognize a similar problem when testing sales items with pricing, especially if the pricing items contain input errors. I published a workaround in commit a6b171a which prevents recording an LRU entry if the domain model instance
contains errors. However, this is not the optimal solution because actually it doesn't fix the bug.

I have a theory how the bug may occur:

  1. submit a form containing a list of items, such as invoicing transaction items or pricing items
  2. if the items contain input errors they cannot be saved
  3. because of the workaround when storing m:n relations in SpringCRM these items are modified first and after that, the main object (invoicing transaction or sales item)
  4. when trying to save the main object it returns null indicating a validation error
  5. however, the items already are modified and marked dirty in the Hibernate session
  6. at a particular time, probably before executing a query, Hibernate persists the session
  7. because the items are invalid they cannot be persisted and produce this error

@dellermann
Copy link
Owner Author

My theory from the last comment seems to be correct. So I fix the related bug with the sales items by adding calls to discard() when input errors are determined. I also analyze the same problem with invoicing items but I could not find out where it goes wrong.

@dellermann
Copy link
Owner Author

I implement a discard() call to the invoicing transaction that should be saved in InvoicingTransactionService, too.

@dellermann
Copy link
Owner Author

This is a duplicate of issue #64.

@dellermann dellermann self-assigned this Dec 27, 2015
@dellermann dellermann reopened this Jan 25, 2016
@dellermann
Copy link
Owner Author

This issue occurred anew in version 2.0.18. Meanwhile, I found the solution:

  1. When one fills out an item of a customer account (InvoicingTransaction), leaves a numeric field like quantity, unit price or tax empty and submits a blank string is submitted to server. Normally, the focusout event is fired when leaving the input control but in the case of submission. However, on some browsers the focusout event is either fired later than submit event or not at all.
  2. The server receives the blank string and tries to convert it to a number during the data binding process.
  3. This produces an error which is stored in the errors property of the item (InvoicingItem). The previous value of the property is retained (in our case: zero).
  4. After that, the method InvoicingTransaction.validate() is called. It checks the validity of the InvoicingTransaction object and all related items. The method suprisingly returns true because all values are valid. The failed bound numeric value is valid because the former value (zero) is validated.
  5. At last, method InvoicingTransaction.save() is called. It first saves the InvoicingTransaction object and than all InvoicingItem objects. Due to an unknown reason the InvoicingItem object cannot be saved, maybe because it has data binding errors. This produces the error stated above.

For now, I fix it by checking not only using validate() but also by calling hasErrors() because the latter reports if there are data binding errors.

@dellermann dellermann modified the milestones: 2.0, 1.5 Jan 25, 2016
dellermann added a commit that referenced this issue Jan 25, 2016
Fix the re-opened issue when storing invalid items in
InvoicingTransaction or PurchaseInvoice.

Fix the missing error display when items are invalid by traversing the
errors property of the items.  Remove the now unneeded tag
<g:renderItemErrors>.
@dellermann
Copy link
Owner Author

Finally fixed in commit c591ba5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant