Magento2: Product Save Not Working

Created on 25 Oct 2016  路  29Comments  路  Source: magento/magento2

The Problem

Product not working in general, so i cant create no products at all.
So what happens is when you try to create a product from the backend, you input some any product name 100% unique ( some thing like dsfkjdskhsdfgdsf ), same goes to url with a .html in the end ( dsfkjdskhsdfgdsf.html ), all necessary fields set.
On a first save attempt it returns you an error saying:

URL key for specified store already exists.

But such URL does not exist

And it keeps on doing that each time. If you change the URL naming after first save attempt to another and try to save.
You get a new error
The file "xxxXXXxxxxXXXXX" doesn't exist or not a file
which is the product image file
After you try upload the same file or any other, with even a different naming, you get the same error. With the same file name from the first try .. and it will ever let you save.
I tried about ten times .. observing whats going on. So when you specify the file for the first time, the file gets uploaded to pub/media/tmp
The on save the file gets moved or deleted, it disappears from that location. (According to Magento 1 the files is moved to media/catalog/product folder)
And after that each attempt to save the product it still searches in pub/media/tmp the first uploaded file, which does not exist.

An NO - no caching enabled .. no opcache or any other caching methods in use.

Environment

Mac OS X El Capitan
Magento 2.1.2 (upgraded from 2.1.1)
PHP 5.6.25
Mysql 5.6.28
All driven on MAMP PRO

Steps to reproduce

See the problem description above. I have described as explicit as possible.

Expected result
Create a new Product

Actual result
Cant Save the Product in any way possible .. and what ever i try to do errors keep on coming up.

screen shot 2016-10-25 at 15 19 40
screen shot 2016-10-25 at 15 03 53
screen shot 2016-10-25 at 15 03 41

Catalog Cannot Reproduce Format is not valid bug report

Most helpful comment

Still an issue in 2.1.6

At least for image upload.

The file "/var/www/user/magento/pub/media/tmp/catalog/product/1/1/11.jpg" doesn't exist or not a file

How to reproduce:
1 - Create a new product and fill out all required pages. Set name for any existing name. upload any image.
2 - Save product. You will see the error "URL key for specified store already exists." - this is expected.
3 - Save product again - unexpected behavior. You will see the error "The file "*" doesn't exist or not a file" any time now.

Seems like magento save uploaded image link to session and do not remove it on errors while file is removed.

All 29 comments

Same thing happens to me

Environment

Docker inside Ubuntu
Magento 2.1

duyleekun

Did you try creating a product with out no Category selected as related ?
In my case i tried to create new products with our adding it to any category and all is ok
when trying to update it to any category it fails with that error
Seems Category URL rewrites are broken for some reason
Also Products in Category view (Front End) not showing

Had this error happen a few times myself.

Magento 2.1.2

+1

I had the same problem under 2.1.0. I upgraded to the latest version (2.1.2) because there was a bug fix that looked like it might fix the problem, but I'm still getting the same thing. My installation is pretty much dead in the water if I can't add products, so this is a major bug. Is there any workaround until the issue is fixed permanently?

Azrob, well you can try creating the products with no categories assigned, that works and after that have to think about how to link them to be displayed in the specific categories.
Maybe doing some straight inserts into the database.

DreLincoln: That did work, thank you.

For anyone else who wants to attempt this, here's what I did:

  1. I added the item without assigning categories, per DreLincoln's suggestion.
  2. For each category I wanted to assign, I found the entity_id in the catalog_category_entity_varchar database table. For example, I wanted to assign the item to three categories and their entity_id's were 32, 126, and 238. I jotted them down.
  3. I found the item's entity_id in the catalog_product_entity table. It was 1285.
  4. I added three rows to the catalog_category_product table, one for each category I wanted to assign to the product. The category_id value was found in step 2 above, and the product_id value was found n step 3. I used 1 for the position value. So I had three new rows with following data: [32, 1285, 1], [126, 1285, 1], and [238, 1285, 1].
  5. I edited the item in the admin backend, checked to see if my categories were assigned correctly, and then saved it again.
  6. I had to delete my var folder to get the item to appear on my site.

Now I'm no Magento guru, so please don't make any changes to your database unless you know what you're doing. And obviously, make a backup first. The steps above worked for me, so use this information at your own risk.

Update on this - might help in solving

So the root of this issue seem to be some configuration error
So lets say you had a store or configured it, so that same product in different categories have the same URL, like it was possible in Magento 1.
Then on save it tries to save multiple records with same URL key to same store.
So the path would show the same either if you try to do it from Category1 or Category2 listing.

The table in the database "url_rewrite" has a Unique Key Constraint (Unique = Url_Path and Store_id)
Which eventually fails since you try to insert 2 records with same url path and store id.

For one Product in my case and 2 categories in 1 Store - it generates 4 records. Since it's a insert multiple action so it does it in one query which eventualy fails and the transaction gets rolled back - you can see this by checking the url_rewrite_id incrementation.

I have deleted this Unique Constraint from the Table for testing purposes, and guess what - now i can save my products with no errors.

Please check the image to see the end result and it is self explanatory why this occurs.

Cheers
strange

Update

looking more into it, it seems that the issue is actually the ROOT Categories generated by the Store on Magento instalation, or Store Creation.
If you did delete your OLD ROOT Categories in admin panel or any other way (Migration Tool) it left Shadow objects of this categories.
Since in the back-end you cant see them no more.
But in the database the records still are present - but the category name missing. So that's why the last 2 records are identical - no category (name or url key)

But the Image path not updating is still present. if you get an error for any reason in your Create method - then the cached image path doesnt get updated, which wont let you continue with your save

Sorry it took so long to get back to this, but I got sidetracked on other projects. I've been waiting to see if a v2.1.3 is released that might fix some of the bugs, but so far no luck there.

The URL rewrites for my site are a disaster. When I generate an XML site map, many of the category and product entries still use the "catalog/product/view/id/" path instead of the SEO path I had assigned. Of the entries that do use the SEO path, some include ",html" at the end and others don't -- even though I specified in the backend that the .html extension should not be used. Plus, some sub-categories include the parent category in the path, like "http://www.whatever.com/seo-path-for-parent-category/seo-path-for-subcategory". It's a mess, and I don't want to launch the site until it is cleaned up. I've tried reindexing and a lot of other things, but nothing has made the URLs adhere to a consistent format.

However, I did look in my catalog_category_entity_varchar table to see if there were any empty category names for the "name" attribute (which for me is attribute_id 45), but there were none. Or am I looking in the wrong place?

At this point I've temporarily given up on adding or editing products. I was doing the workaround as we discussed earlier -- not assigning categories during product entry and doing it later manually in the database -- but I was getting a new error about not having a value for a certain product attribute, even though that attribute did not belong to the default product attribute set I was using. Like I said, it's all just a mess.

Have you made any progress on getting product add/edit to work properly?

After re-reading your posts, I should also mention that I do have a lot of entries in my url_rewrite table where the request_path has no category name and starts with a "/". But the target_path is, for example, "catalog/product/view/id/397/category/26" -- category 26 is the root category for my store (which is not the primary store on my Magento installation), so that seems right to me in a way.

This error seems to trigger in the case if you created new root category/ies - and use them as default for a store view. Even if you delete the default one which came with the install it wont be deleted from the database full way, you will just not see it anymore in the backend.
Or lets say you have 2 ROOT categories one of them is set as a website view default.
So when you try to save a new product, dont know why it tryies to generate URL rewrites for all parents up to ROOT's. So you get at least 2 urls with same path - which triggers the URL key for specified store already exists.
so if your product name is test then for each parent it will generate an url of category-name/test.html
And for ROOT categories will just be /test.html - and as i said it will try to dublicate for each ROOT category. So you end up having 2 URL rewrites with same path.
I solved it for now by removing the Unique index from url_rewrite table

I tried your solution of making the index non-unique and it did work... kind of. I was able to go into an existing item, assign the categories, and save the item. Great!

Then I tried to duplicate an existing item and received an error: "Product with SKU 'CAA936-1' is not linked to product with SKU 'CAC010-1-1'". I was not editing the item with the SKU of CAA936-1 at all, it was CAC010-1. Magento added the extra "-1" on for some reason. How CAA936-1 played into it, I have no clue.

So I tried adding a new item, and all of the information from the item I tried to duplicate was already in there. I made my changes and tried to save it, and I got an error: "The value of attribute "shirt_color" must be set". This attribute had nothing to do with the item type I was trying to save, which was using Attribute Set: Default. Not so great.

Right now, I'm dead in the water. I can't really add any new items and the URL rewrites are not working properly, as I've mentioned before. I keep looking for a v2.1.3 update hoping it will fix the problems, but no luck yet.

Still an issue in Magento 2.1.4

Still an issue in 2.1.5.

I believe the directory path is incorrect.

The file "/private/var/tmp/Applications/MAMP/tmp/php/phpB2mdl6" doesn't exist.

Update - Solved with;

MAMP Pro fix

Change your INI to;
upload_tmp_dir = /private/var/tmp

Still an issue in 2.1.6

At least for image upload.

The file "/var/www/user/magento/pub/media/tmp/catalog/product/1/1/11.jpg" doesn't exist or not a file

How to reproduce:
1 - Create a new product and fill out all required pages. Set name for any existing name. upload any image.
2 - Save product. You will see the error "URL key for specified store already exists." - this is expected.
3 - Save product again - unexpected behavior. You will see the error "The file "*" doesn't exist or not a file" any time now.

Seems like magento save uploaded image link to session and do not remove it on errors while file is removed.

Solved by commenting out upload_tmp_dir in MAMP's php.ini

Magento does not support the operating system you've listed. Please confirm that you can reproduce this issue on a supported platform. For an overview of supported technologies, see System Requirements.

Hi @dmitriyprime, what makes you think the issue is OS-dependent?
Have you seen this comment, for example?
In fact, there are multiple people reporting the same issue down the thread.

Unfortunately, I could not reproduce the issue as you described it. May please let me know if this problem reproducible on latest release version of Magento2?

Still an issue in 2.1.8

Clean install, clean magento, Ubuntu + nginx. Will be reproduced on Ubuntu + apache.
See my comment above - https://github.com/magento/magento2/issues/7178#issuecomment-304791298

I'm facing this problem on version 2.1.7

I'm having the same issue, Magento 2.1.8
"...doesn't exist or not a file"

The part with incorrect image file seems to be fixed in M2.2.

Although it's harder now hot reproduce an error, but by using some 'product_save_before' observer and throwing an error on the first save with image, the second save (without an error) works correctly and keep uploaded image assigned to the product.

@DreLincolin, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0-dev, 2.2.0, 2.1.9

I confirm it can happen on Magento 2.2.0 - Ubuntu

I have been able to fix it with solution provided by @skrobotov

Find your php.ini file and look for upload_tmp_dir
Uncomment by deleting ; at the beginning of the line and add the pub/media/tmp folder.

This fixed the issue in my case. Hope it helps!

+1

In my case (2.2.3) it was happening when i was importing a product with duplicate images. Magento imports an image and moves/removes its file from tmp folder (pub/media/tmp), and thus unable to import the duplicate one.

Same issue 2.3.1 on php7.2

Was this page helpful?
0 / 5 - 0 ratings