Skip to content

Conversation

@dombesz
Copy link
Contributor

@dombesz dombesz commented Nov 6, 2025

Ticket

https://community.openproject.org/work_packages/68705

What are you trying to accomplish?

Bypass work package custom field validation when copying projects.

What approach did you choose and why?

Disable model validation in the WorkPackage::CopyProjectContract.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

Copy link
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

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

I think it would be better to change the copy project succeeds with errors to fail for some other reason (for example create(:work_package, :skip_validations, subject: "", …) to keep the error test and localised error test, and add a separate test that doesn't fail for required custom field.

@dombesz dombesz force-pushed the bug/68705-when-project-is-copied-work-packages-with-empty-mandatory-custom-fields-are-not-copied branch from 6d08938 to a25c708 Compare November 11, 2025 20:01
type.custom_fields << custom_field
end

it "copies the project", :aggregate_failures do
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a check that work package copying failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The work package copying should succeed even if the work package is invalid.

Copy link
Contributor

Choose a reason for hiding this comment

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

The work package, not project

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The work package also.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understood that when copying a project and one of the work packages fails to be copied, it does copy the project, doesn't copy problematic work packages and reports errors

Copy link
Contributor Author

@dombesz dombesz Nov 12, 2025

Choose a reason for hiding this comment

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

That is true only in certain cases, ie. if the validation fails on the work package contract, then the error is reported and the problematic work package is not copied.
However the validations on the work package model itself are skipped (due to the def validate_model? = false). Since the custom fields are validated on the model level, they are skipped too, thus the work package copying will succeed.

@dombesz dombesz merged commit 9ce8b74 into release/16.6 Nov 12, 2025
16 checks passed
@dombesz dombesz deleted the bug/68705-when-project-is-copied-work-packages-with-empty-mandatory-custom-fields-are-not-copied branch November 12, 2025 11:45
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants