Skip to content

Fix set string index 1 for ModelObjects#4211

Merged
kbenne merged 8 commits intoNatLabRockies:developfrom
openstudiocoalition:fix_set_string
Mar 1, 2021
Merged

Fix set string index 1 for ModelObjects#4211
kbenne merged 8 commits intoNatLabRockies:developfrom
openstudiocoalition:fix_set_string

Conversation

@macumber
Copy link
Contributor

@macumber macumber commented Feb 17, 2021

Pull request overview

Please read OpenStudio Pull Requests to better understand the OpenStudio Pull Request protocol.

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Checked behavior in OpenStudioApplication, adjusted policies as needed (src/openstudio_lib/library/OpenStudioPolicy.xml)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@macumber
Copy link
Contributor Author

ASSERT_TRUE(space2);
auto surfaces2 = space2->surfaces();
auto floorSurfaceIt2 = std::find_if(std::begin(surfaces), std::end(surfaces), [](const auto& surface) { return surface.surfaceType() == "Floor"; });
auto floorSurfaceIt2 = std::find_if(std::begin(surfaces2), std::end(surfaces2), [](const auto& surface) { return surface.surfaceType() == "Floor"; });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug in this test unrelated to this pull request

}

// regular field -- name or data
if ((index == 0) && (iddObject().hasNameField())) {
Copy link
Contributor Author

@macumber macumber Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add additional check if this field is a handle here and route that to setName as well to preserve existing behavior.


// check collection NameConflict
if (!uniquelyIdentifiableByName()) {
if (!newName.empty() && iddObject().isRequiredField(*index) && !uniquelyIdentifiableByName()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is mostly to support OutputMeter having an empty name on construction. If we change to OutputMeter Meter Name we can revert this line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change created #4247

OS:Coil:Heating:Electric does not have \required-field on its Name field, and now unicity of name isn't enforced anymore.


// do not set if would violate field NullAndRequired
if ((level > StrictnessLevel::Draft) && newName.empty() && iddObject().isRequiredField(*index)) {
if ((level >= StrictnessLevel::Draft) && newName.empty() && iddObject().isRequiredField(*index)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was enforced at Draft strictness, we don't use Final strictness for anything that I know of

== newSurface.construction().get().cast<LayeredConstruction>().layers());
}

TEST_F(ModelFixture, ModelObject_SetString) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new test to verify the bug fix

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge from #4206 adds a very similar one for at Workspace level, I think both are relevant and I don't see a problem testing twice.

@macumber
Copy link
Contributor Author

macumber commented Feb 20, 2021

Looks like the Python bindings might have issues accessing PyPi, possibly due to not allowing access to secrets on a pull request from a fork?

https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/

NOTE: Try --verbose to see response content.
HTTPError: 403 Forbidden from https://test.pypi.org/legacy/
Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.
Error: Process completed with exit code 1.

BTW, it is so cool to be able to see the build output in GitHub Actions!

macumber and others added 8 commits February 22, 2021 19:09
…ames to empty string because it is wrongly assuming that the name string for WorkspaceObject's is always index 0. For ModelObject's the index is 1 because handle is 0.

Changing this results in some breakage of OutputMeter which uses/abuses the name field to be the E+ meter name.  We may want to change OutputMeter's `Name` field to be `Meter Name`. That seems clear to me but it might break any measure that depends on `meter.name` to give the E+ name. In this commit I kept OutputMeter's `Name` field but marked it as not required (since it is empty) when a meter is first constructed.  This might not be ideal though, we may want to change the field to `Meter Name` to prevent Workspace naming logic from introducing further bugs.

Finally, the Workspace naming logic was protecting the handle field of ModelObjects.  By moving this protection to the name field we may be losing some protection of the handle field.  We may want to add functionality to consider both handle and name fields if they exist?

As with any change to this Workspace level stuff a good review is required.
Comment on lines 434 to 438
if (iddObject().hasNameField()) {
boost::optional<unsigned> nameIndex = iddObject().nameFieldIndex();
if (nameIndex && (*nameIndex == index)) {
return setName(value, checkValidity).has_value();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (iddObject().hasNameField()) {
boost::optional<unsigned> nameIndex = iddObject().nameFieldIndex();
if (nameIndex && (*nameIndex == index)) {
return setName(value, checkValidity).has_value();
}
// regular field -- name or data
if ((iddObject().hasNameField()) && (index == iddObject().nameFieldIndex().get())) {
return setName(value, checkValidity).has_value();
} // name

if hasNameField, I don't think you also need to check if nameIndex exits.

@jmarrec
Copy link
Collaborator

jmarrec commented Feb 22, 2021

@macumber I rebased this branch onto develop and merged #4206 into this (after rebasing it onto develop as well so I could resolve conflicts properly)

@jmarrec
Copy link
Collaborator

jmarrec commented Feb 22, 2021

Looks like the Python bindings might have issues accessing PyPi, possibly due to not allowing access to secrets on a pull request from a fork?

The repo/fork is the one that should have the proper TESTPYPI_TOKEN, so it's expected that it fails. don't worry about it.

@kbenne kbenne merged commit 3650208 into NatLabRockies:develop Mar 1, 2021
@jmarrec
Copy link
Collaborator

jmarrec commented Mar 2, 2021

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WorkspaceObject::setString allows setting invalid names for ModelObjects

3 participants