Ticket #2387 (new defect)

Opened 5 months ago

Last modified 4 months ago

Fields specified in DataObjectDecor not saved if $obj->stat('db') called before $obj->loadExtraDBFields()

Reported by: sminnee Assigned to: aoneil
Type: defect Priority: blocker
Milestone: 2.2.3 Component: (Unknown)
Version: 2.2.2-rc2 Severity: medium effort / impact
Keywords: Cc:
Due date: Harvest Task: (Unknown)
Invoice sent to client: 0 Hours:

Description

The fix has been made in college herald and needs to be merged back.

More broadly, we need to establish a way of testing for and preventing these kind of data loss errors!

The problem was extremely intermittent, but that only makes it more dangerous, inasmuch as it is a major problem that can sneak through into production.

Attachments

Change History

Changed 5 months ago by sharvey

It appeared to only be caused when the site was in live mode. If there's no problem on dev/test then fails on live our tests need to be run for all 3 environments, if we want to be extra careful. I'm not sure why this happened, our Object::add_extension() call was at the very bottom of _config.php, and it didn't initially appear to have any switching based on environments.

Initially when we were debugging, we were sending emails of the Member record before it was written, and after it was written, with our extension fields and values being there, then we moved on into the "manipulation" code block in the write() function on DataObject?. It turns out the DataObjectDecorator? was actually causing the problem, as the extension fields were not being added to the SQL query which eventually wrote the record to the database.

A unit test for the write() method would be very handy, especially for when we're asserting a value for a particular field and we want to ensure this was written in properly. :-)

Changed 5 months ago by sminnee

Further analysis suggests that the problem may be that Object::add_extension('Member', 'RoleClass?') was called too late in the piece.

We should include this quirk in the automated tests for ExtensionTest? / DataObjectTest?.


Statics handling in Object.php is a bit of a mess, and is ultimately the cause of this issue. #2370 touches on this too.

My recommended broad-stroke solution to this is to build a suite of automated tests around Object.php to ensure that the different setters and getters for statics all operate in the same way:

Getters

  • $obj->stat('bla');
  • MyClass::$bla
  • $obj->uninherited('bla', true);

Setters

  • Object::addStaticVars('MyClass?', array('bla' => 'val'));
  • $obj->set_stat('bla', 'val');
  • MyClass::$bla = 'val';

Changed 4 months ago by sminnee

  • milestone set to 2.2.2-rc3*

We should do the quick-fix in 2.2.2, and the bigger fix in 2.2.3.

Changed 4 months ago by sminnee

  • milestone changed from 2.2.2-rc3 to 2.2.3 feature-lock

This was fixed in 2.2.2 on r52448. Moving to the 2.2.3 milestone for the bigger fix.

Changed 4 months ago by sharvey

I called Object::add_extension() instead of DataObject::add_extension()

Perhaps this had something to do with it? Seems like a long shot though.

Note: See TracTickets for help on using tickets.