New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save a new issue and custom fields ignored #10

Closed
tardis4500 opened this Issue Feb 20, 2014 · 7 comments

Comments

2 participants
@tardis4500

tardis4500 commented Feb 20, 2014

I am using Python 2.7.5 with Requests 2.2.1 and Python-Redmine 0.6.0 running against a Redmine 2.3.0 server.

This works:
redmine = Redmine('http://redmine/', key='***')
issue = redmine.issue.create(project_id='lsdt', subject='Test 1')

This doesn't
issue = redmine.issue.new()
issue.project_id = 'lsdt'
issue.subject = 'Test 1'
issue.save()
which results in
redmine.exceptions.ResourceAttrError: Resource doesn't have the requested attribute

and no matter what I have tried with
issue = redmine.issue.create(project_id='lsdt', subject='Test 1', custom_fields=[{'TestField': 1}])
the field TestField is never populated. I have also tried using the update() method to update an existing one and it doesn't work.

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Feb 20, 2014

As for the

issue = redmine.issue.new()
issue.project_id = 'lsdt'
issue.subject = 'Test 1'
issue.save()

I can confirm that this is a bug in Python Redmine and it will be fixed in the next release. Thanks for reporting this.

As for the custom fields, you are using it incorrectly, there is example in the docs:

issue = redmine.issue.create(
    project_id='lsdt',
    subject='Test 1',
    custom_fields=[{'id': TESTFIELD_ID, 'value': TESTFIELD_VALUE}]
)

I.e. you should use the id of the custom field and not a name to set it's value, exactly like in the example.

@maxtepkeev maxtepkeev added the bug label Feb 20, 2014

@maxtepkeev maxtepkeev self-assigned this Feb 20, 2014

@tardis4500

This comment has been minimized.

tardis4500 commented Feb 20, 2014

Ah, I see. Thanks for the info. As a suggestion, begin able to pass in a simple dictionary for custom_fields as with custom_fields={'field': 'val'} in addition to a list as now would be a good enhancement and IMHO more Pythonic.

Thanks!

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Feb 20, 2014

I'm using a list here because you might want to set several fields at once and not one. Of course I can add a check that if a dictionary is passed then we can assume that a single custom field should be set and we should wrap it in a list (Redmine requires a list even if a single custom field is set), but that will create inconsistency from the user point of view imho.

Also, if I am not mistaken it is impossible to set a custom field via it's name, that's why I'm using an id here, but I'll check it to be sure, and if it's possible I will add such a functionality in Python Redmine.

Anyway, thanks for the suggestion.

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Feb 20, 2014

Problem with the issue creation via new() method is fixed in f127314. It will be released to PyPI a little bit later, if you need a fix right now you can always install the latest development version from Github via pip.

@maxtepkeev maxtepkeev closed this Feb 20, 2014

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Feb 20, 2014

I've also checked custom fields, and as I expected, the only way to set them is via id.

@tardis4500

This comment has been minimized.

tardis4500 commented Feb 21, 2014

How do I find out what the ID is for a custom field?

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Feb 22, 2014

If you are using Redmine >= 2.4.0 you can issue an API request via redmine.custom_field.all() and it will return all the available custom fields with their ids.

For Redmine <= 2.4.0 you can go to http://your-redmine-server/custom_fields and click on the custom field you are interested in, then have a look at the browser address bar, there will be an id of the custom field, e.g. http://your-redmine-server/custom_fields/9/edit, 9 is the id of the custom field.

You need to login with a user that has administrative privileges to get access to custom fields.

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