Closed franmomu closed 4 years ago
I don't consider this like a bug, but a bug which was fixed. Why would an order in the createQuery override the table order ?
When a user click on a column to order by 'id' or by 'name', ... It should order by 'id' or by 'name' and only after order by your custom order by 'date'.
If you want to order by date
by default, you should use the datagridValues
.
https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#customizing-the-sort-order
I don't consider this like a bug, but a bug which was fixed. Why would an order in the createQuery override the table order ?
When a user click on a column to order by 'id' or by 'name', ... It should order by 'id' or by 'name' and only after order by your custom order by 'date'.
If you want to order by
date
by default, you should use thedatagridValues
. https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#customizing-the-sort-order
My point was that we shouldn't change something that was working in specific way for a long time without giving some warning first, even if it's a bugfix.
The example I shown was a basic one, but the same applies to multiple field sorting or sorting by COUNT
for example.
My point was that we shouldn't change something that was working in specific way for a long time without giving some warning first, even if it's a bugfix.
What do you propose ?
I added a Fixed
changelog https://github.com/sonata-project/SonataDoctrineORMAdminBundle/releases/tag/3.15.0.
The example I shown was a basic one, but the same applies to multiple field sorting or sorting by
COUNT
for example.
This was never documented as supported. It was just a hack some users found out.
There was a discussion about the expected behaviour of _sort_by
, custom orderBy
, ... here https://github.com/sonata-project/SonataAdminBundle/issues/5929#issuecomment-599680252
The only advice I could give is to override the modelManager this way. https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1004
With this PR we will have both the ability to use custom sortBy and ordering by a column in the next major version.
My point was that we shouldn't change something that was working in specific way for a long time without giving some warning first, even if it's a bugfix.
What do you propose ?
IMO the new behaviour should be optional and enabled by the user or should be reverted.
I added a
Fixed
changelog https://github.com/sonata-project/SonataDoctrineORMAdminBundle/releases/tag/3.15.0.The example I shown was a basic one, but the same applies to multiple field sorting or sorting by
COUNT
for example.This was never documented as supported. It was just a hack some users found out.
I don't think this is a hack... it's where you have access to the query.
There was a discussion about the expected behaviour of
_sort_by
, customorderBy
, ... here sonata-project/SonataAdminBundle#5929 (comment)The only advice I could give is to override the modelManager this way.
1004
With this PR we will have both the ability to use custom sortBy and ordering by a column in the next major version.
My point was that we shouldn't change something that was working in specific way for a long time without giving some warning first, even if it's a bugfix.
What do you propose ?
IMO the new behaviour should be optional and enabled by the user or should be reverted.
So you're not asking for a warning, you're asking for a revert. That's different. I strongly disagree with this. It's not because a bug was here for a long time that the fix should be optional, or reverted.
When using orderBy in the query, you couldn't use the table correctly since you couldn't order by the column. If you don't want to use the column order
feature, just remove the default value from the ManagerInterface or the datagridValues
. I've made PR to allow the null
value.
There are still solutions to have the behaviour you're looking for. But there was no solution to have the correct behaviour before.
I added a
Fixed
changelog https://github.com/sonata-project/SonataDoctrineORMAdminBundle/releases/tag/3.15.0.The example I shown was a basic one, but the same applies to multiple field sorting or sorting by
COUNT
for example.This was never documented as supported. It was just a hack some users found out.
I don't think this is a hack... it's where you have access to the query.
But it's written nowhere that the query order would be applied before the column order.
My point was that we shouldn't change something that was working in specific way for a long time without giving some warning first, even if it's a bugfix.
What do you propose ?
IMO the new behaviour should be optional and enabled by the user or should be reverted.
So you're not asking for a warning, you're asking for a revert. That's different. I strongly disagree with this. It's not because a bug was here for a long time that the fix should be optional, or reverted.
I'm asking for introducing the new behaviour as optional and disabled by default...
When using orderBy in the query, you couldn't use the table correctly since you couldn't order by the column. If you don't want to use the
column order
feature, just remove the default value from the ManagerInterface or thedatagridValues
. I've made PR to allow thenull
value.There are still solutions to have the behaviour you're looking for. But there was no solution to have the correct behaviour before.
I added a
Fixed
changelog https://github.com/sonata-project/SonataDoctrineORMAdminBundle/releases/tag/3.15.0.The example I shown was a basic one, but the same applies to multiple field sorting or sorting by
COUNT
for example.This was never documented as supported. It was just a hack some users found out.
I don't think this is a hack... it's where you have access to the query.
But it's written nowhere that the query order would be applied before the column order.
But we're not going to agree here, so maybe it's better if someone else can help us. WDYT @sonata-project/contributors ?
I'm asking for introducing the new behaviour as optional and disabled by default...
It's like asking for an option with_bug
with true
as the default value.
Plus I already gave you explanation about how to get the behaviour you wanted. So this option is not necessary. The best which could be done would be a HOWTO
somewhere.
But we're not going to agree here, so maybe it's better if someone else can help us. WDYT @sonata-project/contributors ?
In case you didn't see, I gave you another opinion. https://github.com/sonata-project/SonataAdminBundle/issues/5929#issuecomment-599680252
if the user clicks the
I'm not talking here about how it should work... I'm talking about users that use a library and suddenly when they upgrade the library, it shows different results... To me change that behaviour even if it's a bugfix is breaking BC (also taking into account that has worked like this for years and the bug is not critical).
To me change that behaviour even if it's a bugfix is breaking BC.
By definition a bugfix will always change the behaviour of something.
Let's just take the last bugfix on this project https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1009
Before I could filter my list and looking for the id 3.3
, now I can't. Should I call this a BC-break then ? This bug was also here for years and it was not critical. Should we add an option too ?
I'm not talking here about how it should work...
It's should only be the debate. The table should always be able to sort => Bugfix => Patch There si no BC bugfix and BC-break bugfix.
Well I don't think it's the same. Anyway, we have different opinions and that's perfectly fine, let other people decide what to do here.
I am here because we just traced down the cause of lots of test failures in our project was the change introduced to fix issue #997.
I sided with @franmomu. A fix introducing other bugs is not a true fix. As long as the previous method is allowed, we can not afford a hard fail. A deprecation warning will be helpful in this case.
A fix introducing other bugs is not a true fix.
What you're calling bugs are not. It's not because you're used to a wrong behaviour (and you wrote test on it), that fixing this wrong behaviour should be called a "bug". The fact the list was not updated when the user click on the column to sort the list, this was a bug.
As long as the previous method is allowed, we can not afford a hard fail.
Adding sortOrder is still allowed, it's just applied after the table sortBy
as expected for the user.
If you don't want to sort by the column, you should not set a sortBy
value, as already explained in this topic. It takes less than 10 lines to do it the right way and will certainly be the default behaviour in next major. It's not because the bug was in some way useful to you that should call the fix a hard fail.
A deprecation warning will be helpful in this case.
There is no way to add a deprecation warning since you can still use custom addOrderBy, but in the right way, which apply AFTER the table sort.
If we look at others ORM, we can see that there was not intended to add orderBy
in the createQuery.
In DoctrinePhpcr, if you use an oderBy
in the createQuery, it's overriden by the orderBy
here https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/blob/2.x/src/Datagrid/ProxyQuery.php#L137.
So:
This can't be called a BC-break.
Obligatory XKCD
I appreciate both sides here, although I know from experience working with a few apps that use this bundle many admins override the default ordering, especially in filters. For now we've locked our apps at 3.14.0. Perhaps in the future a feature could be considered where table filtering is disabled altogether, enabling the orderBy overrides that people have been using?
Perhaps in the future a feature could be considered where table filtering is disabled altogether, enabling the orderBy overrides that people have been using?
It will be in 4.0. But you can still make this change on your project https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1004
Environment
Sonata packages
Symfony packages
PHP version
Subject
Since https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/997 the order of a list changed
Steps to reproduce
Create an admin an override the
createQuery
method using orderBy:Expected results
To keep sorting as it was before
Actual results
It changed the order list, sorting by id first.