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

Update_fields does not work on a field initially set to None #1088

Open
bip91 opened this issue Jun 24, 2024 · 3 comments
Open

Update_fields does not work on a field initially set to None #1088

bip91 opened this issue Jun 24, 2024 · 3 comments

Comments

@bip91
Copy link

bip91 commented Jun 24, 2024

Hi,

in a Sharepoint list, if we have a field that is not initially set, it is not possible to update it to a new value.

Context :
i = l.get_item_by_id(x)
i.fields # > does not contain any "Status" field as "Status" is not set for this item
i._parent.column_name_cw.value() # > but this contain "Status" value

in that case, update_field raise an error :

i.update_fields({'Status': 'Inactif'})
Traceback (most recent call last):
File "", line 1, in
File "/home/bruno/src/o365/lib/python3.12/site-packages/O365/sharepoint.py", line 154, in update_fields
raise ValueError('"{}" is not a valid internal field name'.format(field))

Explanation :
This is due to the fact that self.fields exists, but not contains the field,
and second condition is never tested.

def _valid_field(self, field):
    # Verify the used field names are valid internal field names
    valid_field_names = self.fields if self.fields \
        else self._parent.column_name_cw.values() \
        if self._parent \
        else None
    if valid_field_names:
        return field in valid_field_names

Solution:
I would suggest to switch the 2 conditions like this :

def _valid_field(self, field):
    # Verify the used field names are valid internal field names
    valid_field_names = self._parent.column_name_cw.values() if self._parent \
                        else self.fields if self.fields \
                        else None
    
    # If no parent is given, and no internal fields are defined assume correct, API will check
    if valid_field_names is None:
        return True
    
    return field in valid_field_names
@alejcas
Copy link
Member

alejcas commented Jul 4, 2024

Is it posible to have a field in self.fields that is not in self._parent.column_name_cw.values()?

@bip91
Copy link
Author

bip91 commented Jul 5, 2024

I don't see any usual case, except perhaps when a field is added.

I have always seen at least self.fields or parent.column_name set
but self.fields contain only fields that have values in Sharepoint list record.
(A bit annoying to rely on that if we want to set a such field).

@alejcas
Copy link
Member

alejcas commented Jul 5, 2024

Can you make a PR with this changes?
Thanks

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

No branches or pull requests

2 participants