Unable to create or update an Asset\Image when saving a Pimcore object - pimcore

My goal is to create / update objects by using a csv file. csv file is fine and allready heavy used.
I wrote a complete script for that, most setSomething() works very well with text, structured Datas etc.. but i'm facing a trouble with the Images. I read the doc twice...
https://pimcore.com/docs/4.6.x/Development_Documentation/Objects/Object_Classes/Data_Types/Image_Types.html
$image = Asset\Image::getByPath("/examples/example1.jpg");
$object->setImage($image);
$object->save();
and that exactly what's i did to create / update $article
$marque = Pimcore\Model\Asset\Image::getByPath("/Catalog/Marques/".$image);
$article->setEarg($marque);
$article->save();
please note that :
$image exists,
$marque is found, and is an instance of Asset\Image
setEarg($marque) is properly defined to set an Image data field
in UI all works fine
cache cleared
Is it possible i misunderstood something ?
I also searched in passed Issues, no luck.
https://github.com/pimcore/pimcore/issues
Maybe someone did face the same problem ? Anc could a hint on how to solve that ?
Regards,

I'm confused...this code is working as it should.
It seems to a cache problem, even if i cleared it. In the UI image did appear after some minutes / hour. Now it appear immedialtly. This question can be closed, but this push me to another one... how did this cache / deffer problem happened. If i find something i will update here.

Related

Empty file being created by node-gpg

I'm trying to use node-gpg: https://github.com/drudge/node-gpg for encrypting/decrypting files using GPG.
snippet of code
a file is being created in the fileDecrypted location but doesn't contain anything
Does anyone know what might be wrong/have encountered a similar issue?
Any help would be appreciated
I also looked into this implementation: https://jaygould.co.uk/2019-01-21-decrypting-gpg-file-node-programatically/
and am doing the same steps but still running into the same problem

Weights&Biases Sweep - Why might runs be overwriting each other?

I am new to ML and W&B, and I am trying to use W&B to do a hyperparameter sweep. I created a few sweeps and when I run them I get a bunch of new runs in my project (as I would expect):
Image: New runs being created
However, all of the new runs say "no metrics logged yet" (Image) and are instead all of their metrics are going into one run (the one with the green dot in the photo above). This makes it not useable, of course, since all the metrics and images and graph data for many different runs are all being crammed into one run.
Is there anyone that has some experience in W&B? I feel like this is an issue that should be relatively straightforward to solve - like something in the W&B config that I need to change.
Any help would be appreciated. I didn't give too many details because I am hoping this is relatively straightforward, but if there are any specific questions I'd be happy to provide more info. The basics:
Using Google Colab for training
Project is a PyTorch-YOLOv3 object detection model that is based on this: https://github.com/ultralytics/yolov3
Thanks! 😊
Update: I think I figured it out.
I was using the train.py code from the repository I linked in the question, and part of that code specifies the id of the run (used for resuming).
I removed the part where it specifies the ID, and it is now working :)
Old code:
wandb_run = wandb.init(config=opt, resume="allow",
project='YOLOv3' if opt.project == 'runs/train' else Path(opt.project).stem,
name=save_dir.stem,
id=ckpt.get('wandb_id') if 'ckpt' in locals() else None)
New code:
wandb_run = wandb.init(config=opt, resume="allow",
project='YOLOv3' if opt.project == 'runs/train' else Path(opt.project).stem,
name=save_dir.stem)

URL Binding issue Vue/webpack

I'm having a peculiar problem when I'm trying to bind an img-tag to a dynamic url.
After finding some similar solutions I found the way to go was by binding the src attribute like this
:src="require(....)"
The problem is however that it only works in the specific format
:src="require('#assets/vendor-'+name+'.svg')"
I'd like to use format src:="require(path)" but I can't seem to get this solution to work.
After some reading some suggestions would point to Webpack causing the issue but currently my knowledge is very limited.
EDIT 1:
Currently I have to extract the name from the JSON-file and add it to that path rather than just using the path found in the JSON-file.
:src="require('#/assets/vendor-' + this.$store.state.vendors[this.cardInfo.vendor].name + '.svg')"
I'd like to make this work
:src="require(this.$store.state.vendors[this.cardInfo.vendor].baseUrl)"

Copy ManyToMany Value

I am currently trying to copy a many-to-many-field from one model to another but running into a bit of trouble. I have been able to create the model fine with a many-to-many-field with a ModelMultipleChoiceField, and the model saves the way I want it to. When I try to copy it to another model, I don't get an error, but nothing happens. Here is the code that I have tried:
author = Author.objects.create(author=self.author)
author = Author.objects.all()[0]
book = entry.approvers.all()
author.pk = None
author.readers.add(*self.readers.all())
I researched this all am and see that M2M models can be tricky. I've tried several variations of the code above and nothing works. I worked my way through several must be an instance errors this am, and that's how I discovered the author = Author.objects.all()[0] command. I no longer get an error but my many-to-many values are not being copied over to another model either. Thanks for any help.
I found this reference on SO and it seems to be what would help me but I tried it and it doesn't work. I am using generic class based views which is probably what is causing me a bit of additional grief.
Class Based Views (CBV), CreateView and request.user with a many-to-many relation
From the example, I used this template for my code but to no avail.
I get needs to have a value for field "id" before this many-to-many relationship can be used.
I just found this reference, Django. Create object ManyToManyField error
It works, and I can then use the following command to post one of the M2M values, but how can I do this without hard coding the pk?
book.reader.add('1')
The above works, but when I try something like
book.reader.add(*self.readers.all())
I've researched this further and this...
author = Author.objects.create(author=self.author)
Plus this alone works...
book.reader.add('1')
Just need to figure out how to replace '1' with a variable name.
After more investigation this may be related to the following issue?
Django: IntegrityError during Many To Many add()
It would seem maybe there is some kind of bug with the bulk_create? The individual add with a hardcoded number works just fine. When I try with the (*self.readers.all()) I don't receive an error message but the manytomany reference is not copied over to the over table. I've seen several articles that say that the commands I'm using work just fine, but perhaps it's for something other than PostgreSQL.
Thanks for any thoughts.
As a newbie, I was doing this work in SAVE. Once I moved it to post_save, the following format worked as expected...
#receiver(post_save, sender='Test.Book')
def post_save(sender,instance, **kwargs):
author = book.objects.create(subject=instance.book)
author.approvers.add(*instance.approvers.all())
As a newbie, I was doing this work by overriding SAVE in my model instead of doing this work in a post_save signal. Changing my approach fixed my issue. The code associated with my correct approach is..
#receiver(post_save,sender='Test.Book')
def post_save(sender,instance,**kwargs):
author = book.objects.create(subject=instance.book)
author.approvers.add(*instance.approvers.all())

How do I set the File Expire Header with Rackspace CloudFiles .NET API

I'm trying to set X-Delete-After and X-Delete-At to a file i'm uploading.
So i tired :
FileMetaData.Add("X-Delete-After", "30");
cloudFilesProvider.UpdateObjectMetadata(inStrContainerID, strDesFileName, FileMetaData);
but the header did not get recognized.
is that the right approach?
Edit: I'm trying to use ICloudFilesMetadataProcessor.ProcessMetadata, but really have no clue how to and am not able to find any documentation.
In the current release of the SDK, you can include the X-Delete-After or X-Delete-At value in the headers argument to the following calls:
IObjectStorageProvider.CreateObject
IObjectStorageProvider.CreateObjectFromFile
Currently there is no way in the SDK to change the value of this header after the file has already been uploaded (e.g. using UpdateObjectMetadata as you suggest in the question would set the values X-Object-Meta-X-Delete-After or X-Object-Meta-X-Delete-After, which is not correct).
Here is a related issue on GitHub:
#167: How to assign version folder
Gopstar --
EDITED:
After more investigation; I set the X-Delete-After to 1500 and the code worked. Sort of. When viewing the file header information via the dashboard, the X-Delete-At was set.
However, the result was correct; the X-Delete-At was equal to what would be 1500 seconds from the time I set it.
Original reply:
I played around; if you set the value higher (for example, I tried X-Delete-After = 3000) it will work.
I do NOT know the lowest number acceptable, but I'm sure someone will chime in with the number.
Hope this give SOME help.

Resources