Skip to content

Throw for DML on filter #2020

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

Merged
merged 1 commit into from
Feb 28, 2019
Merged

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented Feb 25, 2019

As otherwise DML is executed on the whole table.
Though it would be cool to support it.

{
var a = await (s.Query<SimpleEntityWithAssociation>().Take(1).SingleOrDefaultAsync());
var query = a.AssociatedEntities.AsQueryable();
Assert.That(() => query.Delete(), Throws.InstanceOf<NotSupportedException>());
Copy link
Member Author

@bahusoid bahusoid Feb 25, 2019

Choose a reason for hiding this comment

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

@maca88 I've just noticed that async versions of DML extension methods are not used at all in async tests. Is it Async Generator bug?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's a bug and I've created an issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Published a new release 0.13.2 that has the bug fixed.

Copy link
Member

Choose a reason for hiding this comment

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

I do not think we should upgrade the async generator on 5.2x (and even less on previous branches). So we will have to take care of regenerating async files as part of the merge to master I think, in order to take into account the fix now available in master.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thoughts

@hazzik
Copy link
Member

hazzik commented Feb 26, 2019

Should probably go all the way down to 5.0.x

@bahusoid bahusoid changed the base branch from master to 5.0.x February 26, 2019 09:19
@bahusoid bahusoid changed the base branch from 5.0.x to master February 26, 2019 09:20
@bahusoid bahusoid changed the base branch from master to 5.0.x February 26, 2019 09:32
@bahusoid bahusoid force-pushed the throwFilterDml branch 2 times, most recently from 0b1facd to 8d21d3b Compare February 26, 2019 09:38
@hazzik
Copy link
Member

hazzik commented Feb 26, 2019

Too soon, @bahusoid. @fredericDelaporte your thoughts?

@bahusoid

This comment has been minimized.

@fredericDelaporte
Copy link
Member

Technically, I think we should anyway target first 5.2.x, then eventually backport (cherry-pick) to previous ones.
We have already backported some fixes on 5.0.x rather than developing them on it directly, so developing on it then merging up may cause conflicts/history glitches.
About 5.1.x, I think we have already done some backport too, but I have not checked. Anyway, we can start backporting on it instead of developing fixes on it directly, if it is not already started.

So this PR here would go in 5.2.4, and #2011 should drop its release commit for letting it go in its own PR.

@bahusoid bahusoid changed the base branch from 5.0.x to 5.2.x February 26, 2019 16:21
@@ -282,6 +282,9 @@ public virtual void SetResultTransformerAndAdditionalCriteria(IQuery query, NhLi

public int ExecuteDml<T>(QueryMode queryMode, Expression expression)
{
if (Collection != null)
throw new NotSupportedException("DML operations are not supported for filters.");
Copy link
Member

Choose a reason for hiding this comment

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

Should probably be InvalidOperationException. However, I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

As potentially it could be implemented I think NotSupported/NotImplemented exceptions are more appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

NotSupported is fine

@fredericDelaporte fredericDelaporte added this to the 5.2.4 milestone Feb 26, 2019
Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

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

I do not think it deserves a critical label: this is about hard-failing instead of doing unexpected changes in database when attempting to use DML on collection filters (feature actually not available). So fixing it will not restore a critical feature, but "just" prevent some insufficiently tested mistake to corrupt data.

Still worth patching down to 5.0.x for avoiding bad surprises to users.
But it may be a possible breaking change, for those using it in its current state, eventually adding themselves the missing conditions, instead of using a queryable from the session. They may not have a reference to the session where they are doing that. I think we should do it anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants