question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Looks like cell_list_to_rect works wrong

See original GitHub issue

I’ve some problem while writeing values to gsheet. So I debug a little gspread.models.update_cells(). Add some print

def update_cells(self, cell_list, value_input_option='RAW'):
    print(f'Cell list: {cell_list}')
    values_rect = cell_list_to_rect(cell_list)

    start = rowcol_to_a1(min(c.row for c in cell_list), min(c.col for c in cell_list))
    end = rowcol_to_a1(max(c.row for c in cell_list), max(c.col for c in cell_list))

    range_label = '%s!%s:%s' % (self.title, start, end)
    print(f'range_label: {range_label}')
    print(f'values_rect: {values_rect}')
    data = self.spreadsheet.values_update(
        range_label,
        params={
            'valueInputOption': value_input_option
        },
        body={
            'values': values_rect
        }
    )

    return data

This is my output:

Cell list: [<Cell R5C3 9920.0>, <Cell R1C4 'new_column'>, <Cell R5C4 'wow'>]
range_label: Products: Средства для уборки!C1:D5
values_rect: [[9920.0, 'wow']]

It looks like values_rect should be [[None,'new_column'],[None,None],[None,None],[None,None],[9920.0, 'wow']]??? So that means that: values_rect = cell_list_to_rect(cell_list) works bad.

Am I right?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostkucommented, Nov 3, 2018

I’m not sure but it looks like row_offset and col_offset defined wrong. Maybe it should be like:

def cell_list_to_rect(cell_list):
    if not cell_list:
        return []
    rows = defaultdict(lambda: {})
    # row_offset = cell_list[0].row
    # col_offset = cell_list[0].col
    row_offset = min([cell.row for cell in cell_list])
    col_offset = min([cell.col for cell in cell_list])

    for cell in cell_list:
        row = rows.setdefault(int(cell.row) - row_offset, {})
        row[cell.col - col_offset] = cell.value
    if not rows:
        return []

    all_row_keys = chain.from_iterable(row.keys() for row in rows.values())
    rect_cols = range(max(all_row_keys) + 1)
    rect_rows = range(max(rows.keys()) + 1)


    # Return the values of the cells as a list of lists where each sublist
    # contains all of the values for one row. The Google API requires a rectangle
    # of updates, so if a cell isn't present in the input cell_list, then the
    # value will be None and will not be updated.

    return [[rows[i].get(j) for j in rect_cols] for i in rect_rows]
0reactions
burnashcommented, Mar 21, 2020

@taewookim exactly, thank you for spotting this.

Fixed in #613 / v3.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found