Fix libbson deprecated API warning with version compatibility #3792
+8
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix libbson deprecated API warning with version compatibility
Details
This PR fixes deprecation warnings that appear when compiling the cachedb_mongodb module with mongo-c-driver >= 1.29.0. The
bson_as_json()function was deprecated in favor ofbson_as_legacy_extended_json()in mongo-c-driver version 1.29.0 (released October 2024).The warning appears during compilation:
The deprecation was introduced to clarify which JSON format is being produced - legacy extended JSON vs. canonical extended JSON. The function signatures are identical, making this a straightforward API update.
However, many LTS distributions still ship older versions of mongo-c-driver (< 1.29.0), so the code needs to maintain backward compatibility with both the old and new API.
Solution
Add a compatibility macro at the top of
modules/cachedb_mongodb/cachedb_mongodb_dbase.cthat maps the new function name to the old one on older versions:Then update all
bson_as_json()calls tobson_as_legacy_extended_json()throughout the file.This approach:
Compatibility
Fully backward compatible. The macro ensures the code works with:
bson_as_legacy_extended_json()APIbson_as_json()via macroNo runtime behavior changes - the same JSON is produced on all versions.
Closing issues
N/A