BuzzingPixel

Ansel for Craft

Ansel for EE

Treasury

Construct

Category Construct

Dashboard (open an issue here)

All Issues

My Issues

News Contact
Log in

Logged in as

Licenses Purchases Profile Change Password Billing Portal Admin
Log Out
Software
Ansel for Craft Ansel for EE Treasury Construct Category Construct
Support
Dashboard (open an issue here) All Issues My Issues
News Contact
Log in
Logged in as:
Licenses Purchases Profile Change Password Billing Portal Log Out
Dashboard All Issues My Issues
Support Dashboard
  1. Home
  2. Home
  3. Support Dashboard
  4. View Issue

Feed Me import gives SQL error despite not importing into any ansel field

#60 opened by Stian

Subscribe

Details

Complete

Public Issue

Visibility: Public
16 replies
Last reply by TJ Draper
Created 11/1/2017 12:02 PM
Updated 12/2/2017 12:20 PM
Ansel for Craft 1.0.6
CMS Version: 2.6.2994
PHP Version: 7.0.25
MySQL Version: 10.1.22-MariaDB

Description

Solution:

Ansel for Craft 1.0.7 has been released which fixes this issue.

Random products in the import feed gives CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (mandaomm_craft_tenotec.craft_anselImages, CONSTRAINT craft_anselImages_originalAssetId_fk FOREIGN KEY (originalAssetId) REFERENCES craft_assetfiles (id) ON DELETE SET NULL)

I'm positive that the feed isn't set to import images into any ansel fields, and I've validated the feed for errors as well (JSON).

I don't understand why ansel is even triggered. Any ideas?

Much appreciated, cheers!

Replies

  • Stian

    Replied 11/1/2017 12:06 PM, Edited 12/2/2017 12:20 PM

    Sorry, this is the correct error: Ansel dependency injection error: Injected dependency "userModel" does not match expected type "\Craft\UserModel" in class BuzzingPixel\Ansel\Service\AnselImages\SaveRowService

  • TJ Draper

    Replied 11/1/2017 12:48 PM, Edited 12/2/2017 12:20 PM

    Hi Stian,

    If an element has an Ansel field attached to it, Ansel will always run even if there is no data.

    Per our conversation on Slack, I suspect that the issue that the import is essentially running "headless" meaning there is no user. There is an assumption of a user for Ansel in that each image row requires a user ID. I have attached a beta build of Ansel in which I have updated my dependency injection to get the first admin user it can find if a user is not defined on the session. That should hopefully fix the issue. Can you let me know how it goes?

  • Stian

    Replied 11/1/2017 2:49 PM, Edited 12/2/2017 12:20 PM

    Hey, unfortunately the problem persists (same error message).

  • TJ Draper

    Replied 11/1/2017 2:53 PM, Edited 12/2/2017 12:20 PM

    On anselDi.php line 193 where you see $userModel = $app->userSession->getUser();, can you add the following and let me know what the output is?

    $userModel = $app->userSession->getUser();
    echo '<pre>;
    var_dump($userModel);
    die;
    
  • Stian

    Replied 11/1/2017 3:47 PM, Edited 12/2/2017 12:20 PM

    Sure thing. I've PM'ed you the output on slack, as it's quite long.

  • TJ Draper

    Replied 11/2/2017 5:09 PM, Edited 12/2/2017 12:20 PM

    Well, that's befuddling. It's a valid UserModel

  • Stian

    Replied 11/3/2017 5:38 PM, Edited 12/2/2017 12:20 PM

    Good news, it works (almost) now. I just noticed a newer version of Feed Me (I was sure I had the last one, sorry), and I'm not sure if it's that, you, the combo or what, but out of 926 products in the json file, i'm getting Products (NO): Commerce_Product 4478 updated. on almost all of them.

    A (very) few are still causing the import to fail, giving

    Products (NO): CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mandaomm_craft_tenotec`.`craft_anselImages`, CONSTRAINT `craft_anselImages_originalAssetId_fk` FOREIGN KEY (`originalAssetId`) REFERENCES `craft_assetfiles` (`id`) ON DELETE SET NULL)
    

    Any idea on that one?

  • TJ Draper

    Replied 11/3/2017 5:40 PM, Edited 12/2/2017 12:20 PM

    It looks like Ansel is trying to insert a row into the anselImages table but there's no Asset with the ID Ansel is trying to insert.

  • Stian

    Replied 11/3/2017 5:49 PM, Edited 12/2/2017 12:20 PM

    So in other words the json could be refering to an image that doesn't exist on the server?

  • TJ Draper

    Replied 11/3/2017 5:54 PM, Edited 12/2/2017 12:20 PM

    An image that doesn't exist in the database, but yes. It's a MySQL foreign key constraint.

    It is odd since, as you mentioned, the feed isn't supposed to be importing any images into an Ansel field. I’d be curious what data Feed Me is sending to the Ansel field.

  • Stian

    Replied 11/9/2017 7:54 AM, Edited 12/2/2017 12:20 PM

    The fix with for Ansel dependency injection error isn't working after all

  • Kyle

    Replied 11/22/2017 11:48 AM, Edited 12/2/2017 12:20 PM

    Hey guys,

    I've stumbled upon the following error as well:

    Ansel dependency injection error: Injected dependency "userModel" does not match expected type "\Craft\UserModel" in class BuzzingPixel\Ansel\Service\AnselImages\SaveRowService

    The proposed solution makes perfect sense to me, since we are using a cron to process the FeedMe feed. Sooner or later, there is no user and FeedMe fails on any elements that have an Ansel field on it.

    Testing 1.0.7b1 right now. Will get back with results.

    Regards,

  • Kyle

    Replied 11/23/2017 9:54 AM, Edited 12/2/2017 12:20 PM

    The fix implemented in 1.0.7b1 is incomplete and was therefore not working for Stian and me. The following code returns a UserRecord instead of a UserModel:

    if (!$userModel) {
        $userModel = \Craft\UserRecord::model()->findByAttributes([
            'admin' => 1,
        ]);
    }
    

    I've updated the code to populate a UserModel with the record after is has been fetched:

    if (!$userModel) {
        $record = \Craft\UserRecord::model()->findByAttributes([
            'admin' => 1,
        ]);
    
        $userModel  = \Craft\UserModel::populateModel($record);
    }
    

    This fixes all the issues we've been having when using FeedMe and Ansel in one Craft installation. Since they are both good and widely used, I hope this fix will be implemented in the next release :)

    Regards,

  • TJ Draper

    Replied 11/24/2017 9:50 AM, Edited 12/2/2017 12:20 PM

    Hahahahaha. Duh. Right. Okay, give 1.0.7 beta 3 a try (attached in solution area above).

  • Kyle

    Replied 11/25/2017 7:53 AM, Edited 12/2/2017 12:20 PM

    Can confirm that 1.0.7 beta 3 fixes the following 'error' when using Ansel and FeedMe:

    Ansel dependency injection error: Injected dependency "userModel" does not match expected type "\Craft\UserModel" in class BuzzingPixel\Ansel\Service\AnselImages\SaveRowService

  • TJ Draper

    Replied 12/2/2017 12:20 PM

    Ansel for Craft 1.0.7 has been released.

Use Markdown for formatting

Details

Complete

Public Issue

Visibility: Public
16 replies
Last reply by TJ Draper
Created 11/1/2017 12:02 PM
Updated 12/2/2017 12:20 PM
Ansel for Craft 1.0.6
CMS Version: 2.6.2994
PHP Version: 7.0.25
MySQL Version: 10.1.22-MariaDB
Cookie Policy
Privacy Policy
Terms of Service

© 2023 BuzzingPixel, LLC. All rights reserved.