sarumont / py-trello

Python API wrapper around Trello's API
BSD 3-Clause "New" or "Revised" License
945 stars 330 forks source link

card.change_pos does not change card's position in the list of cards #322

Open mals14 opened 4 years ago

mals14 commented 4 years ago

The code does seem to run without error and the json returned by fetch_json function is a valid son with 'pos' changed. Tut no change on the interface. Is this a Trello API issue or py-trello library issue?

On the other hand, card.set_pos("bottom") does work. But card.set_pos(2) does not work.

Any clues as to why this may be happening?

Thank you.

kublaikhan commented 7 months ago

Hopefully you found a way around this, but pos is NOT an index value, it's a positive float value that Trello uses when sorting the cards. So cards with a lower pos value go higher in the list, but when you tried to assign 2, it probably remained the lowest value in your list.

By default Trello seems to increment pos by 16384 and then if you insert a card between two cards Trello will assign a pos to the inserted card that is the average of the neighboring cards. One trouble is that if you assign a pos that collides with another card's pos, or if two pos values are too close together then Trello will recalculate the pos values. I've also found that if you assign very large (valid double) values Trello will adjust them to be much smaller. The best way I've found to do a sort is to sort your cards using py-trello and then set pos values in increments of 16384, like Trello does, and use an offset where necessary to make sure you aren't colliding with any existing pos values.

Some details from here: https://news.ycombinator.com/item?id=10957165

In other words, this issue is not a py-trello issue but a Trello API documentation issue.