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

Fix: Compare Action route #406

Merged

Conversation

BurningDog
Copy link
Contributor

Subject

This fixes the issue where a revision could not be viewing via the CompareAction route.

I am targeting the 1.x branch because it's a bug fix which is backwards compatible.

Closes #405.

Changelog

### Fixed

- The CompareAction route is now working.

XML needs to explicitly define a null using attributes
Otherwise we get a Column not found sql error
@@ -46,8 +46,7 @@ public function __invoke(Request $request, string $className, string $id, ?int $
$newRev = $request->query->get('newRev');
}

$ids = explode(',', $id);
$diff = $this->auditReader->diff($className, $ids, $oldRev, $newRev);
$diff = $this->auditReader->diff($className, $id, $oldRev, $newRev);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array are supposed to be supported

* @param int|string|array $id

and find support array too
public function find($className, $id, $revision, array $options = [])

I would say we try to support something like 3,4,5.

Do it mean this case is broken

if (\is_array($id) && \count($id) > 0) {
?

@wbloszyk @phansys you're using this bundle, do you pass array/multiple ids some times ?

Copy link
Contributor Author

@BurningDog BurningDog Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass $ids as an array to the find() function, then inside

if (\is_array($id) && \count($id) > 0) {
$idKeys = array_keys($id);
$columnName = $idKeys[0];
the values are:

  • $idKeys = [0 => 0]
  • $columnName = 0

...which leads to

$whereSQL .= ' AND e.'.$columnName.' = ?';
being

$whereSQL = "e.rev <= ? AND e.0 = ?" which leads to the sql error.

While I think the type of $id at

public function find($className, $id, $revision, array $options = [])
is correct, I think for the diff() function at
* @param int|string|array $id
it should be * @param int|string $id - because I think a diff is on a single object, by definition.

In that case, the new value becomes:

$whereSQL = "e.rev <= ? AND e.id = ?" which is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...I've added this change into the PR, as CompareAction is the only place which calls the diff() function in the AuditReader.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbloszyk @phansys you're using this bundle, do you pass array/multiple ids some times ?

I'm not using composite ids with this bundle.
This issue was reported before. See #288, #331 #389.

@FlintCIBot
Copy link

Lint errors were found. A patch is also available.

Please see the report: https://flintci.io/repositories/8593/analyses/63517

This comment was posted by FlintCI. It can be disabled in the repository settings.

VincentLanglet
VincentLanglet previously approved these changes Jul 9, 2021
@VincentLanglet VincentLanglet requested a review from a team July 9, 2021 16:55
@VincentLanglet
Copy link
Member

@BurningDog Can you do the same for others actions like in PR https://github.com/sonata-project/EntityAuditBundle/pull/331/files ?

@BurningDog
Copy link
Contributor Author

@VincentLanglet ok, done - I searched for all calls to the find() and findRevisions() functions to ensure that the passed $id is either an int or a string.

@VincentLanglet VincentLanglet requested review from phansys and a team July 11, 2021 09:09
Copy link
Member

@phansys phansys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes disallowing the possibility of using entities with composite ids?
If yes, I think we must add validations to prevent these entities to be marked as auditable from the beginning.

@VincentLanglet
Copy link
Member

Are these changes disallowing the possibility of using entities with composite ids?

If yes, I think we must add validations to prevent these entities to be marked as auditable from the beginning.

Composite ids can be used if you call directly the method of the AuditReader, but cannot be used with these actions.

I dont think it's specifically new since you cannot pass composite ids in a url. Can u ?

Imho if something should be added it would be better to create an issue about, in order to not delay this bugfix

@phansys
Copy link
Member

phansys commented Jul 18, 2021

I dont think it's specifically new since you cannot pass composite ids in a url. Can u ?

Yes, by instance you can use this approach for the ORM manager: "/app/entity/1~42/show".

Imho if something should be added it would be better to create an issue about, in order to not delay this bugfix

I agree.

@VincentLanglet VincentLanglet merged commit ac9b172 into sonata-project:1.x Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compare Revision (CompareAction) route not working
5 participants