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

RUST-2019 Formatter for Bson ignores pretty printing {:#} #491

Closed
mahmoud-moursy opened this issue Aug 17, 2024 · 1 comment · Fixed by #501
Closed

RUST-2019 Formatter for Bson ignores pretty printing {:#} #491

mahmoud-moursy opened this issue Aug 17, 2024 · 1 comment · Fixed by #501
Assignees
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@mahmoud-moursy
Copy link

Versions/Environment

  1. What version of Rust are you using?

rustc 1.82.0-nightly (506052d49 2024-08-16)

  1. What operating system are you using?

Linux

  1. What versions of the driver and its dependencies are you using? (Run
    cargo pkgid mongodb & cargo pkgid bson)
  • bson: registry+https://github.com/rust-lang/crates.io-index#[email protected]
  • mongodb: N/A
  1. What version of MongoDB are you using? (Check with the MongoDB shell using db.version())
    N/A
  2. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
    N/A

Describe the bug

A clear and concise description of what the bug is.

BE SPECIFIC:

  • What is the expected behavior and what is actually happening?
    Expected behaviour:

Bson formatting outputs the following:

{
  "key": "Hello world!"
}

What actually happens:

Bson formatting outputs the following:

{ "key": "Hello world!" }
  • Do you have any ideas on why this may be happening that could give us a
    clue in the right direction?

If you implemented Display manually, then you need to manually check if the user passed in pretty-printing
as a parameter and then change your formatting based on that.

You can check it using formatter.alternate() in your Display implementation.

  • Did this issue arise out of nowhere, or after an update (of the driver,
    server, and/or Rust)?
    The issue has likely existed for as long as the crate has.
  • Are there multiple ways of triggering this bug (perhaps more than one
    function produce a crash)?
    Nope. Only one, specifically. Formatting with {:#?} produces correctly-formatted output.
  • If you know how to reproduce this bug, please include a code snippet here:
let my_hashmap = HashMap::from([
  ("hello", "world!")
]);

let bson_document = bson::to_document(&my_hashmap);

// Incorrect formatting:
println!("{bson_document:#}");

// This, however, is correctly formatted:
println!("{bson_document:#?}");
// It is probably correctly formatted because the derive(Debug) implementation was used.

Thank you.

@abr-egn abr-egn changed the title Formatter for Bson ignores pretty printing {:#} RUST-2019 Formatter for Bson ignores pretty printing {:#} Aug 19, 2024
@abr-egn abr-egn added tracked-in-jira Ticket filed in Mongo's Jira system and removed triage labels Aug 19, 2024
@abr-egn
Copy link
Contributor

abr-egn commented Aug 19, 2024

Thank you for the well-written ticket!

You're quite right that we're not respecting that flag currently; I've filed RUST-2019 to track that. This won't be high priority in our plan for this quarter but we'd certainly welcome a contribution to add it 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants