Skip to content

compareAttributesHash fails if non-persistent struct attributes are defined #146

@DiscountDarcy

Description

@DiscountDarcy

When hydrating an entity from a cache, we stash a couple values in a non-persistent struct on the top level of the entity. This throws an error in 4.2.3 in compareAttributesHash() when it tries save "" to a struct property on this line:

var value = valueIsNotNull ? attributes[ arguments.key ] : "";

As a workaround, we added a filter at the top of compareAttributesHash() to just ignore any attributes passed into that function that aren't defined as attributes on the entity, since we don't care about hashing non-persistent attributes anyway for the purposes of detecting whether the object is dirty.

There's probably a more elegant way to do this, but here's our updated function:

	/**
	 * Computes an hash from a struct of key / value pairs.
	 *
	 * @attributes  A struct of attributes data to compute.
	 *
	 * @return      string
	 */
	public string function computeAttributesHash( required struct attributes ) {
		var validAttrs = this.get_attributes();
		var keys = arguments.attributes.keyArray().filter( ( attr ) => {
			return validAttrs.keyExists( attr );
		} );
		arraySort( keys, "textnocase" );
	
		return hash(
			keys.map( function( key ) {
					var valueIsNotNull = structKeyExists( attributes, arguments.key ) &&
					!isNull( attributes[ arguments.key ] );
					var value = valueIsNotNull ? attributes[ arguments.key ] : "";
					return lCase( arguments.key ) & "=" & value;
				} )
				.toList( "&" )
		);
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions