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

Don't write API deprecations to a file #245

Closed
vicdelfant opened this issue Feb 22, 2023 · 28 comments · Fixed by #332
Closed

Don't write API deprecations to a file #245

vicdelfant opened this issue Feb 22, 2023 · 28 comments · Fixed by #332

Comments

@vicdelfant
Copy link

It appears that if an API deprecation occurs, the SDK attempts to write this deprecation to a file named .last_api_deprecation_warning. This happens in the Http class and does not seem to be configurable behavior.

In our case, we (as most container-based environments) prevent write access to an application's directories except for a few selected ones, and /vendor definitely isn't one of them for obvious reasons. The file_put_contents call unfortunately doesn't have any error handling so a deprecation is now causing exceptions that then trigger our monitoring.

Would it be possible to remove this logic? If I'm being totally honest I don't see the need to write anything directly to a file; that's what libraries such as Monolog or another PSR-compliant library are meant for.

@jordansavant
Copy link

^ This
No composer library should be attempting to write to filesystem, especially a local directory. A simple deprecation warning now produces a fatal error for the entire application.

@wensonsmith
Copy link

Same problem here. I don't understand why write a file in /vendor folder. 🤯

@electricsheep
Copy link

Is there any workaround for this besides forking the library?

This causes a fatal crash and means I can't fetch orders using Order::find() - despite using the most recent API and not requesting any deprecated fields/endpoints, I still get the deprecation warning.

@electricsheep
Copy link

Answering my own question with a workaround I found:

  1. Add the following to composer.json
    "autoload": {
        "psr-4": {
            "Shopify\\Clients\\": "app/Overrides/"
        },
        "exclude-from-classmap": ["vendor/shopify/shopify-api/src/Clients/Http.php"]
    },
  1. Copy the Shopify implementation of the Http class to app/Overrides/ folder.
  2. Remove the deprecation file writing code (below) from the logApiDeprecation function of the copied class (or modify in the way you prefer)
       $warningFilePath = $this->getApiDeprecationTimestampFilePath();

        $lastWarning = null;
        if (file_exists($warningFilePath)) {
            $lastWarning = (int)(file_get_contents($warningFilePath));
        }

        if (time() - $lastWarning < self::DEPRECATION_ALERT_SECONDS) {
            return;
        }

        file_put_contents($warningFilePath, time());
  1. Fix the $version line in the request() function, since it relies on the class directory location
        $version = require dirname(__FILE__) . '/../../vendor/shopify/shopify-api/src/version.php';

You may need to run composer dump-autoload after fixing.

@Jan0707 Jan0707 mentioned this issue Apr 26, 2023
6 tasks
@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label May 30, 2023
@fredden

This comment was marked as outdated.

@omolto
Copy link

omolto commented May 30, 2023

+1

@github-actions github-actions bot removed the Stale label May 31, 2023
@mariusrusu
Copy link

+1

8 similar comments
@nick-dnc
Copy link

+1

@chrisnetonline
Copy link

+1

@appinlet
Copy link

+1

@appinlet
Copy link

+1

@nick-dnc
Copy link

+1

@zchermit
Copy link

zchermit commented Sep 5, 2023

+1

@appinlet
Copy link

+1

@appinlet
Copy link

+1

@mkbodanu4
Copy link

mkbodanu4 commented Oct 12, 2023

Same issue since Oct 02. All the payments stopped working, so I had to comment out code in the library (file src/Clients/Http.php line 208-213) to get the app working

@appinlet
Copy link

+1

@fredden
Copy link
Contributor

fredden commented Oct 29, 2023

From what I can tell, this was fixed in #263 (3ae0ed4) by moving the temporary file into sys_get_temp_dir() instead of writing to a path within vendor/. This was released as part of version 5.0.0 of this library. (My previous comment was wrong.)

@paulomarg, I think this issue can be closed now.

@vicdelfant
Copy link
Author

@paulomarg, I think this issue can be closed now.

It's up to the maintainers of course, but in all honesty I still don't get why a library has to write deprecations to a file. Even though it's just to the temp directory, there's still a file somewhere that can potentially grow to unknown sizes and can't be routed elsewhere.

@fredden
Copy link
Contributor

fredden commented Oct 29, 2023

there's still a file somewhere that can potentially grow to unknown sizes and can't be routed elsewhere.

The file contains only a unix timestamp.

@vicdelfant
Copy link
Author

… which then makes me wonder why we need it at all, or at least from a userland perspective.

It's now turning into a discussion of principles and I know that I am on the annoying end of the spectrum, but the cleaner and less surprises in code (especially code provided by a company such as Shopify), the better :)

@ba-tech-gh
Copy link

It seems like an option to disable this is required, perhaps when doing Context::initialize.

The file .last_api_deprecation_warning makes it impossible to run 2 instances on the same server under different users (something we often do for prod and staging for small apps) because if one of the users creates the file, the other one will be unable to edit it due to lacking ownership.

@appinlet
Copy link

appinlet commented Nov 9, 2023

+1

1 similar comment
@sercanvirlan
Copy link

+1

@PeterDKC
Copy link

PeterDKC commented Feb 3, 2024

The existence of this is so absolutely mind bogglingly absurd. We have a zoom call of 8 people trying to figure out how to get past this right now, it took us 3 days to figure out what was even happening. Because WHY, IN THE NAME OF ALL THE CHILDREN IN THE WORLD, would anyone do something so completely asinine as writing to /tmp/ from the web user out of a f@#$ing vendor/ package????????

If you don't understand why this is not a reasonable thing to do, I have a pamphlet for a high flying career in food service right here for you to peruse.

@appinlet
Copy link

appinlet commented Mar 8, 2024

+1

@Tango459
Copy link

Tango459 commented Apr 5, 2024

+1

fredden added a commit to fredden/shopify-api-php that referenced this issue Apr 5, 2024
This fixes Shopify#245 by no longer writing a timestamp to the filesystem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.