question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Previous metadata values should be unset when updating metadata

See original GitHub issue

When updating metadata, the other bindings (tested with Python, not sure about the others) will unset the previous metadata fields.

E.g., with the Python bindings:

>>> c = stripe.Customer.retrieve("cus_...")
>>> c.metadata
<StripeObject at 0x10577b868> JSON: {
  "A": "is for Aardvark", 
  "B": "is for Baboon"
}
>>> c.metadata = {'C': 'is for Cactus', 'D': 'is for Dachsund'}
>>> c.save()
>>> c = stripe.Customer.retrieve("cus_...")
>>> c.metadata
<StripeObject at 0x10577b868> JSON: {
  "C": "is for Cactus", 
  "D": "is for Dachsund"
}

The bindings correctly reset the 'A' and 'B' keys in the update request:

{
    metadata:
    {
        A: "",
        B: "",
        C: "is for Cactus",
        D: "is for Dachsund"
    }
}

However, when doing the same operation with the Java bindings:

Customer customer = Customer.retrieve("cus_...");

System.out.println("Before update:");
System.out.println(customer.getMetadata());

Map<String, Object> customerParams = new HashMap<String, Object>();
Map<String, String> customerMetadata = new HashMap<String, String>();
customerMetadata.put("C", "is for Cactus");
customerMetadata.put("D", "is for Dachsund");
customerParams.put("metadata", customerMetadata);

customer.update(customerParams);

customer = Customer.retrieve("cus_...");

System.out.println("After update:");
System.out.println(customer.getMetadata());

The result is:

Before update:
{B=is for Baboon, A=is for Aardvark}
After update:
{B=is for Baboon, A=is for Aardvark, C=is for Cactus, D=is for Dachsund}

The update request only sent the new metadata keys, but didn’t reset the previously existing ones:

{
    metadata:
    {
        C: "is for Cactus",
        D: "is for Dachsund"
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jimdanzcommented, Nov 18, 2015

This is intended behavior. stripe-java objects do not implement “save” methods that take the in-memory object and persist it to the API. Instead, stripe-java objects implement an explicit update method, the contract of which is that it sends its map of parameters directly over the wire.

To unset a metadata key in stripe-java, pass empty string as the value. For instance, customerMetadata.put("D", "");

0reactions
jimdanzcommented, Nov 18, 2015

Ah sorry didn’t realize that stripe-java overrides our handling of empty string. Thanks for catching!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating metadata without deleting the previous value
Question is how add next ID without erase previous. Now after every update in metafield saved last user ID, need save all ID's...
Read more >
Trying to update Values in Standard Object from metaData
apex - Trying to update Values in Standard Object from metaData - Salesforce Stack Exchange. Stack Overflow for Teams – Start collaborating and ......
Read more >
Create Metadata in a Space and Add it to a Page - Confluence
To add a default value to any metadata field simply edit the Metadata set(s) the field belongs in. Click on pencil symbol if...
Read more >
Updating and Maintaining your Metadata - YouTube
This 20 minute webinar will provide an overview of updating, evaluating, and maintaining the metadata records you register with Crossref.
Read more >
Edit Metadata: Component reference - Azure Machine Learning
Use Edit Metadata anytime you need to modify the definition of a column, typically to meet requirements for a downstream component. For example, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found