To use a FEN as a key to compare positions, the en passant field should only be set when the pawn can actually be taken. This allows transposed chess positions to have matching FENs, even if the last move in one of the positions was a 2-square pawn move without a possible en passant capture.
The FEN specification states that the en passant field should be set on every 2-square pawn move, but it is useful to be able to disable this for the aforementioned reason (using a FEN as a comparison key). Lichess, for example, seems to only set the en passant field when the pawn can be taken, so that they properly compare positions in their opening explorer.
To use a FEN as a key to compare positions, the en passant field should only be set when the pawn can actually be taken. This allows transposed chess positions to have matching FENs, even if the last move in one of the positions was a 2-square pawn move without a possible en passant capture.
The FEN specification states that the en passant field should be set on every 2-square pawn move, but it is useful to be able to disable this for the aforementioned reason (using a FEN as a comparison key). Lichess, for example, seems to only set the en passant field when the pawn can be taken, so that they properly compare positions in their opening explorer.