Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Regression in 1.1 model binding for model types without default constructor #5698

Closed
Tragetaschen opened this issue Jan 18, 2017 · 9 comments

Comments

@Tragetaschen
Copy link
Contributor

Tragetaschen commented Jan 18, 2017

In 1.1, the ComplexTypeModelBinderProvider started to check for a default constructer: d09e921. This breaks my application.

I'm using a controller that calls TryUpdateModelAsync with a preconstructed IValueProvider and model instances:

await TryUpdateModelAsync(
    model,
    model.GetType(),
    prefix,
    valueProvider,
    a => true
);

Some of the model types don't have default constructors, most notably because I need some external dependencies for IValidatableObject. These model types now don't work anymore and my entire controller action fails.

The above commit doesn't really contain any information why this change was introduced and the binder itself doesn't require a default contsructor when the model object is pre-constructed

@Tragetaschen
Copy link
Contributor Author

As a workaround, I have added a default constructor to the model types throwing a NIE.

@rynowak
Copy link
Member

rynowak commented Jan 19, 2017

/cc @dougbu @Eilon - this might be patch worthy

IIRC we did this to try and improve the error message when a non-constructible type was used with CTMB. It would seem we regressed TryUpdateModel which uses the same infrastructure.

@dougbu
Copy link
Member

dougbu commented Jan 19, 2017

Some of the background here can be found in issue #4895. @kichalla fixed that bug in PR #5368.

I agree the check for a parameterless constructor should be moved from ComplexTypeModelBinderProvider to ComplexTypeModelBinder and be done only when bindingContext.Model == null.

Nit: CanCreateModel() is a horribad name for a method which primarily checks whether value provider data is available for properties in the model. Might want to clean that up when adding a check that's actually about the ability to create the model.

@Eilon Eilon added this to the 1.1.1 milestone Jan 19, 2017
@Eilon
Copy link
Member

Eilon commented Jan 19, 2017

We will try to get this fixed in the patch.

@Eilon
Copy link
Member

Eilon commented Feb 8, 2017

This patch bug is approved. Please use the normal code review process w/ a PR and make sure the fix is in the correct branch, then close the bug and mark it as done.

@Eilon
Copy link
Member

Eilon commented Feb 8, 2017

@kichalla FYI this is an approved patch bug on your plate.

@Eilon
Copy link
Member

Eilon commented Feb 10, 2017

Done?

@kichalla
Copy link
Member

Sorry yeah done.

@Tragetaschen
Copy link
Contributor Author

Yay!

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

No branches or pull requests

5 participants