Fix wrong lenses in RawTherapee (duplicated lens id)
Have you experienced that your image editing program sometimes selects the wrong lens for a picture? You might experience an issue caused by duplicated lens IDs...
Background
When you take an image with a digital camera, the camera writes the camera settings and hardware to your image file. This includes the lens used by you. Unfortunately a lens usually does not come with a name: Instead it has parameters (apertures, focal lenghts) and an ID number. As there is no central registry for a menufacturer to register their IDs, multiple lenses share the same. Below is the output of the exiftool
command:
$ exiftool -minfocallength -maxfocallength -minaperture -maxaperture -lenstype -lensid -g IMG_9228.CR2
---- MakerNotes ----
Lens Type : Canon EF 85mm f/1.2L USM or Sigma or Tamron Lens
Max Focal Length : 70 mm
Min Focal Length : 24 mm
Max Aperture : 2.8
Min Aperture : 23
---- Composite ----
Lens ID : Sigma 24-70mm f/2.8 IF EX DG HSM or Tamron SP 24-70mm f/2.8 Di VC USD
The data below "MakerNotes" is what is saved in the file (or better: the best textual representation the tool has to offer). The "Lens Type" is shared between the Canon EF 85mm f/1.2L USM, an unspecified Sigma or an unspecified Tamron lens. The focal lengths and apertures are listed below. Under the "Composite" heading are the conclusions of the tool: It may either be the Sigma 24-70mm or the Tamron 24-70mm... Unfortunately it cannot be discerned anymore, but it has excluded the Canon EF one. RawTherapee chooses one of the remaining lenses - in my case RawTherapee chooses the Sigma one, but I shot with the Tamron one.
Fix: Partial profile
You can see the currently used “profile” of an image in the top-right corner:

There are full profiles (e.g. reasonable defaults) and partial ones with only a few settings. To create such a partial profile, first apply the settings you want to have stored. For correcting the lens, select the correct lens in the “Profile Lens Correction” screen, and include the correct name in the metadata tab. If you already changed other metadata fields, you may need to use an unmodified image.


To save the profile Control+Click on the Save icon next to the profile selector in the top-right corner. After you chose the settings to be included in your profile, you will be asked for a filename (I suggest the name of the lens).

After this step you will find your freshly created profile below “My profiles”. You can already manually apply it to any already existing images.

Automatically apply newly misidentified images
To apply your profile automatically to any image with the “wrong” lens, you can set up dynamic profiles: You can set rules when which profile is applied.
First enable the (Dynamic) profile for your raw photos:

Under the Dynamic Profile Rules, first add your actual default profile you want to use, I chose Standard Film Curve - ISO Low. Then, add another profile: This time enter wrongfully identified name in the “Lens” field, and select your previously created profile:

This has the effect that all newly opened images with this lens will have their lens correct and metadata overridden. In every overview, RawTherapee will still show the old one though.

Open a previously unedited image, and check if it works. Either reset the processing profile (this will revert your edits!) on an edited picture, or open a previously untouched picture.
