Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: last_modified_t needs to be a number and not a string #9705

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/update_all_products.pl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
my $compute_main_countries = '';
my $prefix_packaging_tags_with_language = '';
my $fix_non_string_ids = '';
my $fix_string_last_modified_t = '';
my $assign_ciqual_codes = '';
my $obsolete = 0;
my $fix_obsolete;
Expand Down Expand Up @@ -175,6 +176,7 @@
"fix-zulu-lang" => \$fix_zulu_lang,
"fix-rev-not-incremented" => \$fix_rev_not_incremented,
"fix-non-string-ids" => \$fix_non_string_ids,
"fix-string-last-modified-t" => \$fix_string_last_modified_t,
"user-id=s" => \$User_id,
"comment=s" => \$comment,
"run-ocr" => \$run_ocr,
Expand Down Expand Up @@ -252,6 +254,7 @@
and (not $fix_nutrition_data_per)
and (not $fix_nutrition_data)
and (not $fix_non_string_ids)
and (not $fix_string_last_modified_t)
and (not $compute_sort_key)
and (not $remove_team)
and (not $remove_category)
Expand Down Expand Up @@ -334,6 +337,11 @@
$query_ref->{_id} = {'$type' => "long"};
}

# Query products that have the last_modified_t field stored as a number
if ($fix_string_last_modified_t) {
$query_ref->{last_modified_t} = {'$type' => "string"};
}

# On the producers platform, require --query owners_tags to be set, or the --all-owners field to be set.

if ((defined $server_options{private_products}) and ($server_options{private_products})) {
Expand Down Expand Up @@ -743,11 +751,17 @@
my $current_last_modified_t = $product_ref->{last_modified_t} // 0;
if ($current_last_modified_t != $change_last_modified_t) {
print STDERR "-> fixing last_modified_t from $current_last_modified_t to $change_last_modified_t";
$product_ref->{last_modified_t} = $change_last_modified_t;
# print statement above makes $change_last_modified_t a a string
$product_ref->{last_modified_t} = $change_last_modified_t + 0;
}
}
}

if ($fix_string_last_modified_t) {
# Make sure last_modified_t is stored as a number
$product_ref->{last_modified_t} += 0;
}

# Fix zulu lang, bug https://github.com/openfoodfacts/openfoodfacts-server/issues/2063

if ($fix_zulu_lang) {
Expand Down
Loading