Skip to content

Model equality check is broken in many models #2140

@benortiz

Description

@benortiz

Description

Across many models with "additionalAttributes", the equality check effectively only checks if additionalAttributes is equal. See lines 273 and 274 below.

def ==(o)
return true if self.equal?(o)
self.class == o.class &&
application == o.application &&
ci_pipeline_fingerprints == o.ci_pipeline_fingerprints &&
contacts == o.contacts &&
dd_service == o.dd_service &&
description == o.description &&
extensions == o.extensions &&
integrations == o.integrations &&
languages == o.languages &&
lifecycle == o.lifecycle &&
links == o.links &&
schema_version == o.schema_version &&
tags == o.tags &&
team == o.team &&
tier == o.tier &&
type == o.type
additional_properties == o.additional_properties
end

Since this is so widespread, it seems like an issue with code generation. When regenerated with the fix to this issue, the individual code might change like so:

           tier == o.tier &&
-          type == o.type
+          type == o.type &&
           additional_properties == o.additional_properties

To Reproduce

Initialize any two different models that can have additionalAttributes and run an equality comparison:

> DatadogAPIClient::V2::ServiceDefinitionV2Dot2.new == DatadogAPIClient::V2::ServiceDefinitionV1.new
=> true

Or initialize the same model but with different properties and run an equality comparison:

> DatadogAPIClient::V2::ServiceDefinitionV2Dot2.new(dd_service: "serviceA") == DatadogAPIClient::V2::ServiceDefinitionV2Dot2.new(dd_service: "serviceB")
=> true

Expected behavior

  1. No two objects of different classes ought to be equivalent.
  2. When comparing instances of the same classes with different model property values, they should not be equivalent.

Environment and Versions:
A clear and precise description of your setup:

  • Ruby 3.2.6
  • DatadogAPIClient 2.28.1
  • Also present in master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions