Error during update special attributes on product

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi!
I add the special attribute and call it YEAR. Its optional - like 2012, 2013, 2014, 2015.
And when I trying to update it from a form Admin/Product/Edit I retrieve an error. I have a nop from the box so seems it's like a bug.
Image:

http://imgur.com/a/MMGHx



Server Error in '/' Application.
The UPDATE statement conflicted with the FOREIGN KEY constraint "ProductSpecificationAttribute_SpecificationAttributeOption". The conflict occurred in database "NOP", table "dbo.SpecificationAttributeOption", column 'Id'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: The UPDATE statement conflicted with the FOREIGN KEY constraint "ProductSpecificationAttribute_SpecificationAttributeOption". The conflict occurred in database "PROSVETEComDB", table "dbo.SpecificationAttributeOption", column 'Id'.
The statement has been terminated.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): The UPDATE statement conflicted with the FOREIGN KEY constraint "ProductSpecificationAttribute_SpecificationAttributeOption". The conflict occurred in database "PROSVETEComDB", table "dbo.SpecificationAttributeOption", column 'Id'.
The statement has been terminated.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +3277272
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +345
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +5002
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) +492
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +3152
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +704
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +512
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +406
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +104
   System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +438
   System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) +759
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +221

[UpdateException: An error occurred while updating the entries. See the inner exception for details.]
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +485
   System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +453
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +235
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +210
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +285
   System.Data.Entity.Internal.InternalContext.SaveChanges() +149

[DbUpdateException: An error occurred while updating the entries. See the inner exception for details.]
   System.Data.Entity.Internal.InternalContext.SaveChanges() +272
   Nop.Data.EfRepository`1.Insert(T entity) +197
   Nop.Services.Logging.DefaultLogger.InsertLog(LogLevel logLevel, String shortMessage, String fullMessage, Customer customer) +267
   Nop.Services.Logging.LoggingExtensions.FilteredLog(ILogger logger, LogLevel level, String message, Exception exception, Customer customer) +150
   Nop.Web.Framework.Controllers.BaseController.LogException(Exception exc) +156
   Nop.Admin.Controllers.BaseAdminController.OnException(ExceptionContext filterContext) +148
   System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception) +175
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +164
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1590.0
7 years ago
Did you do any customization in your DB and core code?
7 years ago
No no! I already said id. This is nopcommerce 3.9 from the box. So it's a like a bug. Check it please.
7 years ago
The error is here

http://imgur.com/a/MMGHx

ProducController.cs method:
[HttpPost]
public virtual ActionResult ProductSpecAttrUpdate(ProductSpecificationAttributeModel model)
{


This code:

if (int.TryParse(model.ValueRaw, out specificationAttributeOptionId))
                    psa.SpecificationAttributeOptionId = specificationAttributeOptionId;


model.ValueRaw = "2016" but after execution psa.CustomValue = NULL. So seems problem is with this.
7 years ago
art_MOO wrote:
No no! I already said id. This is nopcommerce 3.9 from the box. So it's a like a bug. Check it please.


I have tested just now, it is working fine.

You can get nop 3.90 stable version from ==>https://www.nopcommerce.com/downloads.aspx

Note: you can test with new fresh browser.
7 years ago
Oke i got it! Thanks for assistance!
7 years ago
Ok! Can we please go back to this question please??

So let's take a look more carefully:
This is a response from ProductSpecAttrList:

{"ExtraData":null,"Data":[{"AttributeTypeId":0,"AttributeTypeName":"Option","AttributeId":6,"AttributeName"
:"Year","ValueRaw":"2016","AllowFiltering":false,"ShowOnProductPage":true,"DisplayOrder":0,"SpecificationAttributeOptionId"
:17,"Id":28,"CustomProperties":{}}],"Errors":null,"Total":1}


We have spec attribute Year with value 2016. So we will try to change AllowFiltering to Yes.
Then we will come to this code:

ProductSpecAttrUpdate

                if (int.TryParse(model.ValueRaw, out specificationAttributeOptionId))
                    psa.SpecificationAttributeOptionId = specificationAttributeOptionId;

In this case Model.ValueRaw = 2016 and it will parce INT!
So i m not sure that it works from the box. Could u please check again?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.