Skip to content
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

Confusing error when creating a choice field on a list #873

Closed
Midnighter opened this issue Jun 22, 2024 · 2 comments
Closed

Confusing error when creating a choice field on a list #873

Midnighter opened this issue Jun 22, 2024 · 2 comments
Labels

Comments

@Midnighter
Copy link

There's an example for creating a choice field using the add_choice_field method, which adapted to a list looks like:

from office365.sharepoint.client_context import ClientContext
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = client.web.lists.get_by_title("My List")

field_name = create_unique_name("ChoiceField")

choices = ["Not Started", "In Progress", "Completed", "Deferred"]
field = target_list.fields.add_choice_field(title=field_name, values=choices).execute_query()

That example works completely fine for me, too. However, what confuses me is that when I want to use FieldCreationInformation I get a 400 Bad Request. This confuses me greatly, as the add_choice_field seems to do the same thing internally.

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.fields.creation_information import FieldCreationInformation
from office365.sharepoint.fields.type import FieldType
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = client.web.lists.get_by_title("My List")

field_name = create_unique_name("ChoiceField")

choices = ["Not Started", "In Progress", "Completed", "Deferred"]
field = target_list.fields.add(FieldCreationInformation(field_name, FieldType.Choice, choices=choices)).execute_query()

This happens on Python 3.11 with version 2.5.10.

@Midnighter
Copy link
Author

I found that this is also reported in #861 although that was using version 2.5.3 of the package.

@vgrem vgrem added bug labels Jun 26, 2024
@vgrem
Copy link
Owner

vgrem commented Jun 26, 2024

Greetings,

thank you for catching this issue and providing the test case!

This issue has been addressed a new 2.5.11 version

@vgrem vgrem closed this as completed Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants