python-redmine icon indicating copy to clipboard operation
python-redmine copied to clipboard

adding custom fields to project

Open laaber opened this issue 1 year ago • 1 comments

Hi,

I'm trying to add custom fields to an existing project. This seems not to work, while updating existing custom fields in a project works fine. The documentation's example https://python-redmine.com/resources/project.html#save isn't saying if the custom_fields exist in the example and get updated or if they're added to the project. So I'm not sure if it's a bug or not.

You can reproduce it by creating a custom field via the GUI, e.g. a simple true/false one, and a project that has no custom fields enabled in its settings (here "templates")

Then run blub = redmine.project.get('templates', include = ['trackers', 'issue_categories', 'enabled_modules' ]) and dir(blub.custom_fields) will show "redminelib.exceptions.ResourceAttrError: Resource doesn't have the requested attribute" correctly.

Then proceed as in the manual:

blub.custom_fields  = [{'id': 71, 'value': 0 }]
dir(blub.custom_fields) # now populated
blub.save()

Now open the project in the UI and there's still no custom field enabled.

Activating the custom field via the UI and doing the above again will show no error when running dir(blub.custom_fields) after retrieving the project and I can happily toggle the custom field's value on and off as expected.

laaber avatar Jun 11 '24 10:06 laaber

Hi @laaber

This is an expected behaviour from Redmine and its API. You won't be able to work with custom fields unless they're enabled for the needed resource i.e. project, issue etc.

maxtepkeev avatar Jun 20 '24 17:06 maxtepkeev

Closing this due to inactivity.

maxtepkeev avatar Jul 06 '24 09:07 maxtepkeev