Bug 114848

Summary: ContentItem#beforeSave method does not always set the content section
Product: [Retired] Red Hat Enterprise CMS Reporter: Daniel BerrangĂ© <berrange>
Component: domainAssignee: ccm-bugs-list
Status: CLOSED RAWHIDE QA Contact: Jon Orris <jorris>
Severity: medium Docs Contact:
Priority: medium    
Version: nightly   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-02-11 22:39:26 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 113496    

Description Daniel Berrangé 2004-02-03 15:41:37 UTC
Description of problem:
During the APLAWS bulk content import, the 'section_id' field (aka the
Item <-> COntnetSection association) is never set on any of the
folders. This is despite the presence of the following code in
beforeSave():

            if (getContentSection() == null) {
                setDefaultContentSection();
            }

Now, this code is in turn wrapped in a isNew() check, so it is only
run once when the object is first created. Copious log4j debugging,
however, indicates that its not being run *EVER*.

Now, the first thing in the beforeSave method is a call 

        if (get(ANCESTORS) == null) {
            setAncestors(getParent());
        }

Since the ANCESTORS denormalaization is written in Java, I suspected
this might be triggering a save, thus reseting the isNew flag. So I
added some more log4j debugging either side of this method. The
beforeSave method now looks something like:


        s_log.debug(m_bpad + "Start Before save " + this + " " +
m_wasNew + " " + isNew());
        m_wasNew = isNew();

        if (get(ANCESTORS) == null) {
            setAncestors(getParent());
        }
        s_log.debug(m_bpad + "Next Before save " + this + " " +
m_wasNew +  " " + isNew());


        if (isNew()) {
            // Set the default content type.
            s_log.debug("Before save one-time birth stuff");

            // Set the default content section.
            if (getContentSection() == null) {
                setDefaultContentSection();
            }
        }
        s_log.debug(m_bpad + "End Before save " + this + " " +
m_wasNew + " " + isNew());
        m_bpad = m_bpad.substring(2);


NB, the 'm_bpad' variable I was using to see if beforeSave was in fact
re-entrant. After this I ran my program again and got the following logs:

--Start Before save [com.arsdigita.cms.Folder:{id=46003}]NM true true
--Start After save [com.arsdigita.cms.Folder:{id=64}] false false
--End After save [com.arsdigita.cms.Folder:{id=64}] false false
--Next Before save [com.arsdigita.cms.Folder:{id=46003}]M true false
--End Before save [com.arsdigita.cms.Folder:{id=46003}]M true false
--Start After save [com.arsdigita.cms.Folder:{id=46003}]M true false
--End After save [com.arsdigita.cms.Folder:{id=46003}] true false

NB, 64 is the ROOT folder & does have a content section set. 46003 is
the new folder I'm creating.

So, this shows that the call to setAncestors is indeed clearing the
'isNew' flag before the end of the beforeSave() method.

Code which deals with isNew() and save observers has hisotrically been
rather error prone, that it may be worth considering a pair of
beforeFirstSave() and afterFirstSave() observers to elminiate the need
for application programmers to hand-craft these semantics.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 Richard Li 2004-02-05 16:21:29 UTC
ashah fixed @40019. the general problem of isNew has been noted
numerous times in many tickets; we want to fix it but that will take a
bit more time.

Comment 2 Jon Orris 2004-02-10 22:36:25 UTC
Dan, can you confirm that Archit's fix corrects your specific problem?


Comment 3 Daniel Berrangé 2004-02-11 15:53:00 UTC
Yes it works fine now.